Merge pull request #890 from unoplatform/dev/jela/net9
fix: Adjust static assets generation sequence
This commit is contained in:
Коммит
5fb8ba5a99
|
@ -79,6 +79,7 @@ namespace Uno.Wasm.Bootstrap
|
|||
[Required]
|
||||
public string WasmShellMode { get; set; } = "";
|
||||
|
||||
public ITaskItem[] ExistingStaticWebAsset { get; set; } = [];
|
||||
|
||||
public ITaskItem[] EmbeddedResources { get; set; } = [];
|
||||
|
||||
|
@ -145,7 +146,7 @@ namespace Uno.Wasm.Bootstrap
|
|||
|
||||
public override bool Execute()
|
||||
{
|
||||
IntermediateOutputPath = TryConvertLongPath(IntermediateOutputPath);
|
||||
IntermediateOutputPath = IntermediateOutputPath;
|
||||
_intermediateAssetsPath = Path.Combine(IntermediateOutputPath, "unowwwrootassets");
|
||||
Directory.CreateDirectory(_intermediateAssetsPath);
|
||||
|
||||
|
@ -161,6 +162,7 @@ namespace Uno.Wasm.Bootstrap
|
|||
GenerateIndexHtml();
|
||||
GenerateEmbeddedJs();
|
||||
GenerateConfig();
|
||||
RemoveDuplicateAssets();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -170,6 +172,26 @@ namespace Uno.Wasm.Bootstrap
|
|||
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 @@ namespace Uno.Wasm.Bootstrap
|
|||
|
||||
private (string fullPath, string relativePath) GetFilePaths(ITaskItem item)
|
||||
{
|
||||
// This is for project-local defined content
|
||||
var baseSourceFile = item.GetMetadata("DefiningProjectDirectory");
|
||||
|
||||
if (item.GetMetadata("TargetPath") is { } targetPath && !string.IsNullOrEmpty(targetPath))
|
||||
if (item.GetMetadata("RelativePath") is { } relativePath && !string.IsNullOrEmpty(relativePath))
|
||||
{
|
||||
var fullPath = Path.IsPathRooted(item.ItemSpec) ? item.ItemSpec : Path.Combine(baseSourceFile, item.ItemSpec);
|
||||
Log.LogMessage(MessageImportance.Low, $"RelativePath '{relativePath}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})");
|
||||
|
||||
// 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))
|
||||
{
|
||||
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 @@ namespace Uno.Wasm.Bootstrap
|
|||
}
|
||||
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 @@ namespace Uno.Wasm.Bootstrap
|
|||
{
|
||||
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 @@ namespace Uno.Wasm.Bootstrap
|
|||
{
|
||||
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}");
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@
|
|||
</Target>
|
||||
|
||||
<Target Name="GenerateUnoWasmAssets"
|
||||
BeforeTargets="ResolveProjectStaticWebAssets;_UnoWasmNativeForBuild"
|
||||
BeforeTargets="ResolveStaticWebAssetsInputs;PrepareInputsForWasmBuild;ResolveJSModuleStaticWebAssets;_UnoWasmNativeForBuild"
|
||||
DependsOnTargets="_UnoAdjustCompatibility">
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -252,14 +252,14 @@
|
|||
Include="@(_AllChildProjectItemsWithTargetPath)"
|
||||
Condition=" '%(_AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest' OR '%(_AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'Always' " />
|
||||
|
||||
<Content Remove="$(WasmPWAManifestFile)" />
|
||||
<ContentWithTargetPath Remove="$(WasmPWAManifestFile)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ShellTask_v0
|
||||
AotProfile="$(WasmAotProfilePath)"
|
||||
Assembly="$(IntermediateOutputPath)$(TargetFileName)"
|
||||
AssemblyName="$(AssemblyName)"
|
||||
Assets="@(Content);@(_UnoWasmCopyToOutputAssets)"
|
||||
Assets="@(ContentWithTargetPath);@(_UnoWasmCopyToOutputAssets)"
|
||||
ContentExtensionsToExclude="$(WasmShellContentExtensionsToExclude)"
|
||||
CSPConfiguration="$(WasmShellCSPConfiguration)"
|
||||
CurrentProjectPath="$(MSBuildProjectDirectory)"
|
||||
|
@ -282,16 +282,38 @@
|
|||
PWAManifestFile="$(WasmPWAManifestFile)"
|
||||
ReferencePath="@(_UnoWasmBootstrapAssembliesForReferenceCopyLocalPaths)"
|
||||
RunAOTCompilation="$(RunAOTCompilation)"
|
||||
ExistingStaticWebAsset="@(StaticWebAsset)"
|
||||
Optimize="$(Optimize)"
|
||||
WasmBuildNative="$(WasmBuildNative)"
|
||||
WasmShellMode="$(WasmShellMode)"
|
||||
WebAppBasePath="$(WasmShellWebAppBasePath)"
|
||||
>
|
||||
<Output TaskParameter="StaticWebContent" ItemName="Content" />
|
||||
<Output TaskParameter="StaticWebContent" ItemName="_UnoStaticWebContent" />
|
||||
<Output TaskParameter="NativeFileReference" ItemName="NativeFileReference" />
|
||||
<Output TaskParameter="FilteredAotProfile" PropertyName="_FilteredAotProfile" />
|
||||
</ShellTask_v0>
|
||||
|
||||
<DefineStaticWebAssets
|
||||
CandidateAssets="@(_UnoStaticWebContent)"
|
||||
FingerprintCandidates="$(StaticWebAssetsFingerprintContent)"
|
||||
FingerprintPatterns="@(StaticWebAssetFingerprintPattern)"
|
||||
RelativePathPattern="wwwroot/**"
|
||||
SourceType="Discovered"
|
||||
SourceId="$(PackageId)"
|
||||
ContentRoot="$(MSBuildProjectDirectory)\wwwroot\"
|
||||
BasePath="$(StaticWebAssetBasePath)"
|
||||
AssetMergeSource="$(StaticWebAssetMergeTarget)">
|
||||
<Output TaskParameter="Assets" ItemName="StaticWebAsset" />
|
||||
</DefineStaticWebAssets>
|
||||
|
||||
<DefineStaticWebAssetEndpoints
|
||||
CandidateAssets="@(StaticWebAsset)"
|
||||
ExistingEndpoints="@(StaticWebAssetEndpoint)"
|
||||
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
|
||||
>
|
||||
<Output TaskParameter="Endpoints" ItemName="StaticWebAssetEndpoint" />
|
||||
</DefineStaticWebAssetEndpoints>
|
||||
|
||||
<PropertyGroup Condition=" '$(_FilteredAotProfile)' != '' ">
|
||||
<!-- Override the user's profile with the filtered one -->
|
||||
<WasmAotProfilePath>$(_FilteredAotProfile)</WasmAotProfilePath>
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
<WasmShellMonoRuntimeExecutionMode Condition="$([MSBuild]::IsOsPlatform('Linux'))">InterpreterAndAOT</WasmShellMonoRuntimeExecutionMode>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
|
||||
}
|
|
@ -37,11 +37,11 @@
|
|||
<!-- Add linked content first to validate directory creation from links -->
|
||||
<Content Include="..\.editorconfig" Link="AdditionalContent\%(FileName)%(Extension)" />
|
||||
<Content Include="../nuget.config" Link="AdditionalContent\%(FileName)%(Extension)" />
|
||||
<Content Include="AdditionalContent\SomeContent01.txt">
|
||||
<Content Include="$(MSBuildThisFileDirectory)AdditionalContent\SomeContent01.txt">
|
||||
<UnoDeploy>Package</UnoDeploy>
|
||||
</Content>
|
||||
<Content Include="AdditionalContent/SomeContent02.txt" />
|
||||
<Content Include="AdditionalContent/SomeContent03.txt" UnoDeploy="Root" />
|
||||
<Content Include="AdditionalContent/SomeContent04.txt" UnoDeploy="None" />
|
||||
<Content Include="$(MSBuildThisFileDirectory)AdditionalContent/SomeContent02.txt" />
|
||||
<Content Include="$(MSBuildThisFileDirectory)AdditionalContent/SomeContent03.txt" UnoDeploy="Root" />
|
||||
<Content Include="$(MSBuildThisFileDirectory)AdditionalContent/SomeContent04.txt" UnoDeploy="None" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Загрузка…
Ссылка в новой задаче