diff --git a/Readme.md b/Readme.md index ea3005583..a1dadd1a0 100644 --- a/Readme.md +++ b/Readme.md @@ -82,6 +82,8 @@ The documentation for this file [can be found here](https://github.com/mono/link ## Publishing the build results The easiest way to publish the build results is to use the Visual Studio publish menu on your project. This will allow to use all the features provided by the standard experience, as described in the [Deploy to Azure App Service](https://docs.microsoft.com/en-us/visualstudio/deployment/quickstart-deploy-to-azure?view=vs-2017). +For deeper integration in the publishing pipeline, the `WasmShellOutputPackagePath` property is defined by the bootstrapper after the `BuildDist` target, which contains the path to the generated `package_XXX` content. + ## Serve the Wasm app through Windows Linux Subsystem Using Windows 10, serving the app through a small Web Server is done through WSL. diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index 0f40c27a4..f71318f20 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -155,6 +155,9 @@ public partial class ShellTask_v0 : Microsoft.Build.Utilities.Task public bool GenerateAOTProfile { get; set; } = false; + [Output] + public string? OutputPackagePath { get; private set; } + public override bool Execute() { try @@ -179,10 +182,10 @@ public override bool Execute() ExtractAdditionalJS(); ExtractAdditionalCSS(); CleanupDist(); - MergeConfig(); TouchServiceWorker(); PrepareFinalDist(); GenerateConfig(); + MergeConfig(); GenerateHtml(); TryCompressDist(); @@ -345,10 +348,10 @@ private void CompressFiles(string[] filesToCompress, string method, Action { - var compressedPathBase = Path.Combine(_workDistPath, "_compressed_" + method); + var compressedPathBase = Path.Combine(_distPath, "_compressed_" + method); var compressedFileName = fileName; - compressedFileName = compressedFileName.Replace(_workDistPath, compressedPathBase); + compressedFileName = compressedFileName.Replace(_distPath, compressedPathBase); DirectoryCreateDirectory(Path.GetDirectoryName(compressedFileName)); @@ -910,11 +913,10 @@ select AssemblyDefinition.ReadAssembly(asmPath) private void PrepareFinalDist() { - IEnumerable ComputeHash(string file) { using var hashFunction = SHA1.Create(); - using var s = File.OpenRead(file); + using var s = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); return hashFunction.ComputeHash(s); } @@ -928,8 +930,22 @@ IEnumerable ComputeHash(string file) using var hashFunction = SHA1.Create(); var hash = string.Join("", hashFunction.ComputeHash(allBytes).Select(b => b.ToString("x2"))); - _remoteBasePackagePath = $"package_{hash}"; - _finalPackagePath = TryConvertLongPath(Path.Combine(_distPath, _remoteBasePackagePath)); + if (_shellMode == ShellMode.Node) + { + _remoteBasePackagePath = ""; + _finalPackagePath = _distPath; + OutputPackagePath = _distPath; + } + else + { + _remoteBasePackagePath = $"package_{hash}"; + _finalPackagePath = TryConvertLongPath(Path.Combine(_distPath, _remoteBasePackagePath)); + OutputPackagePath = _finalPackagePath.Replace(@"\\?\", ""); + } + + // Create the path if it does not exist (particularly if the path is + // not in a set of folder that exists) + Directory.CreateDirectory(_finalPackagePath); if (Directory.Exists(_finalPackagePath)) { @@ -938,9 +954,25 @@ IEnumerable ComputeHash(string file) Directory.Move(_workDistPath, _finalPackagePath); + MoveFileSafe(Path.Combine(_finalPackagePath, "web.config"), Path.Combine(_distPath, "web.config")); + MoveFileSafe(Path.Combine(_finalPackagePath, "server.py"), Path.Combine(_distPath, "server.py")); + RenameFiles(_finalPackagePath, "dll"); } + private static void MoveFileSafe(string source, string target) + { + if (File.Exists(source) && source != target) + { + if (File.Exists(target)) + { + File.Delete(target); + } + + File.Move(source, target); + } + } + /// /// Renames the files to avoid quarantine by antivirus software such as Symantec, @@ -1200,13 +1232,13 @@ private void MergeConfig() var tempFile = Path.GetTempFileName(); try { - var monoJsPath = Path.Combine(_workDistPath, "dotnet.js"); + var monoJsPath = Path.Combine(_finalPackagePath, "dotnet.js"); using (var fs = new StreamWriter(tempFile)) { - fs.Write(File.ReadAllText(Path.Combine(_workDistPath, "mono-config.js"))); - fs.Write(File.ReadAllText(Path.Combine(_workDistPath, "uno-config.js"))); - fs.Write(File.ReadAllText(Path.Combine(_workDistPath, "uno-bootstrap.js"))); + fs.Write(File.ReadAllText(Path.Combine(_finalPackagePath, "mono-config.js"))); + fs.Write(File.ReadAllText(Path.Combine(_finalPackagePath, "uno-config.js"))); + fs.Write(File.ReadAllText(Path.Combine(_finalPackagePath, "uno-bootstrap.js"))); fs.Write(File.ReadAllText(monoJsPath)); } diff --git a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets index de5df4d7b..638d34908 100644 --- a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets +++ b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets @@ -122,7 +122,7 @@ - + ReferencePath="@(_AssembliesForReferenceCopyLocalPaths)"> + + diff --git a/src/Uno.Wasm.Sample/Uno.Wasm.Sample.csproj b/src/Uno.Wasm.Sample/Uno.Wasm.Sample.csproj index c4e5b2f62..99df4582e 100644 --- a/src/Uno.Wasm.Sample/Uno.Wasm.Sample.csproj +++ b/src/Uno.Wasm.Sample/Uno.Wasm.Sample.csproj @@ -31,7 +31,7 @@ - + @@ -49,7 +49,7 @@ <_AdditionalFile Include="nuget.config" /> - +