From 3ddf67b48eff8912f4d44c295f451d79edc4c1b1 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Fri, 23 Oct 2020 07:53:57 -0400 Subject: [PATCH] Allow WasmAppBuilder to run after the publish step. Change the (#43742) wasm sample to use publish. --- src/mono/netcore/sample/wasm/console/Makefile | 6 +- .../netcore/sample/wasm/console/WasmSample.csproj | 26 ++++++-- .../mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 69 ++++++++++++++-------- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/mono/netcore/sample/wasm/console/Makefile b/src/mono/netcore/sample/wasm/console/Makefile index 40cbf04..960f458 100644 --- a/src/mono/netcore/sample/wasm/console/Makefile +++ b/src/mono/netcore/sample/wasm/console/Makefile @@ -1,13 +1,17 @@ TOP=../../../../../.. +ifeq ($(V),) DOTNET_Q_ARGS=--nologo -v:q -consoleloggerparameters:NoSummary +else +DOTNET_Q_ARGS=--nologo +endif CONFIG?=Release all: build build: - $(TOP)/.dotnet/dotnet build $(DOTNET_Q_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj + $(TOP)/.dotnet/dotnet publish $(DOTNET_Q_ARGS) /p:TargetArchitecture=wasm /p:TargetOS=Browser /p:Configuration=$(CONFIG) WasmSample.csproj clean: rm -rf bin diff --git a/src/mono/netcore/sample/wasm/console/WasmSample.csproj b/src/mono/netcore/sample/wasm/console/WasmSample.csproj index c84daac..baa4083 100644 --- a/src/mono/netcore/sample/wasm/console/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/console/WasmSample.csproj @@ -9,8 +9,24 @@ $(ArtifactsBinDir)microsoft.netcore.app.runtime.browser-wasm\$(Configuration)\runtimes\browser-wasm\ $(MSBuildThisFileDirectory)obj\$(Configuration)\wasm $(MSBuildThisFileDirectory)bin\$(Configuration)\publish + true + link + false + true + browser-wasm + false + + + + + $(ArtifactsBinDir)microsoft.netcore.app.runtime.browser-wasm\$(Configuration) + + + + + @@ -28,18 +44,16 @@ - + - - - + + Assemblies="@(BundleAssemblies)"/> diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 3726a93..348e33b 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -16,8 +16,6 @@ using Microsoft.Build.Utilities; public class WasmAppBuilder : Task { - // FIXME: Document - [Required] public string? AppDir { get; set; } [Required] @@ -35,8 +33,9 @@ public class WasmAppBuilder : Task // https://github.com/dotnet/icu/tree/maint/maint-67/icu-filters public string? IcuDataFileName { get; set; } = "icudt.dat"; - [Required] + // Either one of these two need to be set public ITaskItem[]? AssemblySearchPaths { get; set; } + public ITaskItem[]? Assemblies { get; set; } public int DebugLevel { get; set; } public ITaskItem[]? ExtraAssemblies { get; set; } public ITaskItem[]? SatelliteAssemblies { get; set; } @@ -107,42 +106,62 @@ public class WasmAppBuilder : Task throw new ArgumentException($"File MainJS='{MainJS}' doesn't exist."); if (!InvariantGlobalization && string.IsNullOrEmpty(IcuDataFileName)) throw new ArgumentException("IcuDataFileName property shouldn't be empty if InvariantGlobalization=false"); + if (AssemblySearchPaths == null && Assemblies == null) + throw new ArgumentException("Either the AssemblySearchPaths or the Assemblies property needs to be set."); var paths = new List(); _assemblies = new SortedDictionary(); - // Collect and load assemblies used by the app - foreach (var v in AssemblySearchPaths!) + if (AssemblySearchPaths != null) { - var dir = v.ItemSpec; - if (!Directory.Exists(dir)) - throw new ArgumentException($"Directory '{dir}' doesn't exist or not a directory."); - paths.Add(dir); - } - _resolver = new Resolver(paths); - var mlc = new MetadataLoadContext(_resolver, "System.Private.CoreLib"); + // Collect and load assemblies used by the app + foreach (var v in AssemblySearchPaths!) + { + var dir = v.ItemSpec; + if (!Directory.Exists(dir)) + throw new ArgumentException($"Directory '{dir}' doesn't exist or not a directory."); + paths.Add(dir); + } + _resolver = new Resolver(paths); + var mlc = new MetadataLoadContext(_resolver, "System.Private.CoreLib"); - var mainAssembly = mlc.LoadFromAssemblyPath(MainAssembly); - Add(mlc, mainAssembly); + var mainAssembly = mlc.LoadFromAssemblyPath(MainAssembly); + Add(mlc, mainAssembly); - if (ExtraAssemblies != null) - { - foreach (var item in ExtraAssemblies) + if (ExtraAssemblies != null) { - try - { - var refAssembly = mlc.LoadFromAssemblyPath(item.ItemSpec); - Add(mlc, refAssembly); - } - catch (System.IO.FileLoadException) + foreach (var item in ExtraAssemblies) { - if (!SkipMissingAssemblies) + try { - throw; + var refAssembly = mlc.LoadFromAssemblyPath(item.ItemSpec); + Add(mlc, refAssembly); + } + catch (System.IO.FileLoadException) + { + if (!SkipMissingAssemblies) + throw; } } } } + else + { + string corelibPath = string.Empty; + foreach (var v in Assemblies!) + { + if (v.ItemSpec.EndsWith ("System.Private.CoreLib.dll")) + corelibPath = Path.GetDirectoryName (v.ItemSpec)!; + } + _resolver = new Resolver(new List() { corelibPath }); + var mlc = new MetadataLoadContext(_resolver, "System.Private.CoreLib"); + + foreach (var v in Assemblies!) + { + var assembly = mlc.LoadFromAssemblyPath(v.ItemSpec); + Add(mlc, assembly); + } + } var config = new WasmAppConfig (); -- 2.7.4