diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index ececf6965..c24fdeaad 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -79,6 +79,7 @@ public partial class ShellTask_v0 : Task [Required] public string WasmShellMode { get; set; } = ""; + public ITaskItem[] ExistingStaticWebAsset { get; set; } = []; public ITaskItem[] EmbeddedResources { get; set; } = []; @@ -145,7 +146,7 @@ public partial class ShellTask_v0 : Task public override bool Execute() { - IntermediateOutputPath = TryConvertLongPath(IntermediateOutputPath); + IntermediateOutputPath = IntermediateOutputPath; _intermediateAssetsPath = Path.Combine(IntermediateOutputPath, "unowwwrootassets"); Directory.CreateDirectory(_intermediateAssetsPath); @@ -161,6 +162,7 @@ public override bool Execute() GenerateIndexHtml(); GenerateEmbeddedJs(); GenerateConfig(); + RemoveDuplicateAssets(); } finally { @@ -170,6 +172,26 @@ public override bool Execute() return true; } + private void RemoveDuplicateAssets() + { + // Remove duplicate assets from the list to be exported. + // They might have been imported from the build pass. + + var existingAssets = StaticWebContent + .Where(s => ExistingStaticWebAsset.Any(e => e.ItemSpec == s.ItemSpec || e.GetMetadata("FullPath") == s.GetMetadata("FullPath"))) + .ToArray(); + + foreach (var existingAsset in existingAssets) + { + Log.LogMessage(MessageImportance.Low, $"Existing asset to remove [{existingAsset.ItemSpec}]"); + } + + // remove existingAssets from StaticWebContent + StaticWebContent = StaticWebContent + .Where(s => !existingAssets.Contains(s)) + .ToArray(); + } + private void GeneratedAOTProfile() { var useAotProfile = !GenerateAOTProfile && UseAotProfile; @@ -209,25 +231,31 @@ private void Cleanup() private (string fullPath, string relativePath) GetFilePaths(ITaskItem item) { - // This is for project-local defined content - var baseSourceFile = item.GetMetadata("DefiningProjectDirectory"); + if (item.GetMetadata("RelativePath") is { } relativePath && !string.IsNullOrEmpty(relativePath)) + { + Log.LogMessage(MessageImportance.Low, $"RelativePath '{relativePath}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); - if (item.GetMetadata("TargetPath") is { } targetPath && !string.IsNullOrEmpty(targetPath)) + // This case is mainly for shared projects and files out of the baseSourceFile path + return (item.GetMetadata("FullPath"), relativePath); + } + else if (item.GetMetadata("TargetPath") is { } targetPath && !string.IsNullOrEmpty(targetPath)) { - var fullPath = Path.IsPathRooted(item.ItemSpec) ? item.ItemSpec : Path.Combine(baseSourceFile, item.ItemSpec); + Log.LogMessage(MessageImportance.Low, $"TargetPath '{targetPath}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); // This is used for item remapping - return (fullPath, targetPath); + return (item.GetMetadata("FullPath"), targetPath); } else if (item.GetMetadata("Link") is { } link && !string.IsNullOrEmpty(link)) { - var fullPath = Path.IsPathRooted(item.ItemSpec) ? item.ItemSpec : Path.Combine(baseSourceFile, item.ItemSpec); + Log.LogMessage(MessageImportance.Low, $"Link '{link}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); // This case is mainly for shared projects and files out of the baseSourceFile path - return (fullPath, link); + return (item.GetMetadata("FullPath"), link); } else if (item.GetMetadata("FullPath") is { } fullPath && File.Exists(fullPath)) { + Log.LogMessage(MessageImportance.Low, $"FullPath '{fullPath}' (ItemSpec: {item.ItemSpec})"); + var sourceFilePath = item.ItemSpec; if (sourceFilePath.StartsWith(CurrentProjectPath)) @@ -242,7 +270,9 @@ private void Cleanup() } else { - return (Path.Combine(baseSourceFile, item.ItemSpec), item.ItemSpec); + Log.LogMessage(MessageImportance.Low, $"Without metadata '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); + + return (item.GetMetadata("FullPath"), item.ItemSpec); } } @@ -331,9 +361,9 @@ private void ExtractAdditionalJS() { var (fullSourcePath, relativePath) = GetFilePaths(projectResource); - if (relativePath.Contains("WasmScripts")) + if (fullSourcePath.Contains("WasmScripts")) { - var scriptName = Path.GetFileName(relativePath); + var scriptName = Path.GetFileName(fullSourcePath); Log.LogMessage($"Embedded resources JS {scriptName}"); @@ -368,9 +398,9 @@ private void ExtractAdditionalCSS() { var (fullSourcePath, relativePath) = GetFilePaths(projectResource); - if (relativePath.Contains("WasmCSS")) + if (fullSourcePath.Contains("WasmCSS")) { - var cssName = Path.GetFileName(relativePath); + var cssName = Path.GetFileName(fullSourcePath); Log.LogMessage($"Embedded CSS {cssName}"); diff --git a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets index c9b9772e3..38cf47f61 100644 --- a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets +++ b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets @@ -237,7 +237,7 @@ @@ -252,14 +252,14 @@ Include="@(_AllChildProjectItemsWithTargetPath)" Condition=" '%(_AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest' OR '%(_AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'Always' " /> - + - + + + + + + + + + $(_FilteredAotProfile) diff --git a/src/Uno.Wasm.MixedModeSample/Uno.Wasm.MixedModeSample.csproj b/src/Uno.Wasm.MixedModeSample/Uno.Wasm.MixedModeSample.csproj index 5331fcf43..85c1f2a1f 100644 --- a/src/Uno.Wasm.MixedModeSample/Uno.Wasm.MixedModeSample.csproj +++ b/src/Uno.Wasm.MixedModeSample/Uno.Wasm.MixedModeSample.csproj @@ -10,10 +10,6 @@ InterpreterAndAOT - - - - diff --git a/src/Uno.Wasm.MixedModeSample/wwwroot/dummy.json b/src/Uno.Wasm.MixedModeSample/wwwroot/dummy.json new file mode 100644 index 000000000..0db3279e4 --- /dev/null +++ b/src/Uno.Wasm.MixedModeSample/wwwroot/dummy.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/src/Uno.Wasm.Sample/Uno.Wasm.Sample.projitems b/src/Uno.Wasm.Sample/Uno.Wasm.Sample.projitems index 8d930d462..0ad10c512 100644 --- a/src/Uno.Wasm.Sample/Uno.Wasm.Sample.projitems +++ b/src/Uno.Wasm.Sample/Uno.Wasm.Sample.projitems @@ -37,11 +37,11 @@ - + Package - - - + + + \ No newline at end of file