Skip to content

Commit

Permalink
fix: Ensure wwwroot assets are copied properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Sep 25, 2024
1 parent d4ecf76 commit b206247
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
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)" />
</ItemGroup>
</Target>

Expand Down

0 comments on commit b206247

Please sign in to comment.