Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure wwwroot assets are copied properly #18300

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\Assets\Icons\icon_foreground.scale-300.png" />
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\Assets\Icons\icon_foreground.scale-400.png" />

<!-- wwwroot -->
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\..\staticwebapp.config.json" />
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\..\web.config" />

<!-- Validate json files handling -->
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\test_root_asset.json" />
<_AssetsToValidate Include="$(WasmShellOutputPackagePath)\test_root_asset_not_included.json" MustNotExist="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,45 @@
<Error Text="The Wasm SDK is not enabled" Condition=" '$(_UnoUseMicrosoftNETSdkWebAssembly)' != 'true' OR '$(UsingMicrosoftNETSdkWebAssembly)' != 'true' " />
</Target>

<Target Name="_UnoValidateSelfAssets"
BeforeTargets="AfterBuild">

<ItemGroup
Condition=" '$(TargetFramework)' == 'net9.0-windows10.0.19041' OR '$(TargetFramework)' == 'net9.0-desktop' ">
<!-- Validates that assets are properly propagated to the output folder, regardless of their "copy to output" value -->
<_AssetsToValidate Include="$(OutputPath)Assets\SharedAssets.md" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-100.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-125.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-150.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-200.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-300.png" />
<_AssetsToValidate Include="$(OutputPath)Assets\Icons\icon_foreground.scale-400.png" />
</ItemGroup>

<ItemGroup
Condition="'$(TargetFramework)'=='net9.0-browserwasm'">

<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\SharedAssets.md" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-100.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-125.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-150.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-200.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-300.png" />
<_AssetsToValidate Include="$(OutputPath)wwwroot\Assets\Icons\icon_foreground.scale-400.png" />

<!-- wwwroot -->
<_AssetsToValidate Include="$(OutputPath)\wwwroot\staticwebapp.config.json" />
<_AssetsToValidate Include="$(OutputPath)\wwwroot\web.config" />
</ItemGroup>

<Error Text="Missing asset %(_AssetsToValidate.Identity)"
Condition="'@(_AssetsToValidate)'!='' AND '%(_AssetsToValidate.MustNotExist)'!='true' AND !exists('%(_AssetsToValidate.Identity)')" />

<Error Text="Invalid existing asset %(_AssetsToValidate.Identity)"
Condition="'@(_AssetsToValidate)'!='' AND '%(_AssetsToValidate.MustNotExist)'=='true' AND exists('%(_AssetsToValidate.Identity)')" />

</Target>

</Project>
26 changes: 23 additions & 3 deletions src/Uno.Sdk/targets/Uno.Common.Wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<SupportedPlatform Remove="@(SupportedPlatform)" />
<SupportedPlatform Include="browserwasm" />

<!-- net9.0 validation of CA1418 is case sensitive -->
<SupportedPlatform Include="BrowserWasm" />
<SdkSupportedTargetPlatformVersion Include="$(TargetPlatformVersion)" />
Expand Down Expand Up @@ -66,7 +66,7 @@

See https://github.com/dotnet/sdk/blob/e3c62139dd25af2b7593a2cde702261f20822e47/src/StaticWebAssetsSdk/Sdk/Sdk.StaticWebAssets.StaticAssets.ProjectSystem.props#L36
-->

<!-- Get all files included by the Web Sdk, except ones from the Assets folder -->
<_ContentToUpdate
Include="@(Content)"
Expand All @@ -83,13 +83,33 @@
<!-- Remove the files Web SDK included files. This will also remove duplicates, regardless of the metadata -->
<Content Remove="@(_ContentToUpdate)"
Condition="'%(_ContentToUpdate.IsWebSdk)'=='true' AND '%(_ContentToUpdate.IsDefaultItem)'!='true'" />

<!-- Add back the non-websdk content -->
<Content Include="@(_NonWebSdkContent)" KeepDuplicates="false" />

<!-- Cleanup -->
<_ContentToUpdate Remove="@(_ContentToUpdate)"/>
<_NonWebSdkContent Remove="@(_NonWebSdkContent)"/>

</ItemGroup>
</Target>

<Target Name="_UnoAdjustWwwrootContent"
BeforeTargets="AssignTargetPaths">

<ItemGroup>
<_wwwRootContentToUpdate Include="$(MSBuildProjectDirectory)/$(WasmProjectFolder)/wwwroot/**" />

<Content Remove="@(_wwwRootContentToUpdate)" />

<Content Include="@(_wwwRootContentToUpdate)">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<UnoDeploy>Root</UnoDeploy>
<!-- net9+ compatibility -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

<_wwwRootContentToUpdate Remove="@(_wwwRootContentToUpdate)" />
jeromelaban marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Target>

Expand Down
Loading