Skip to content

Commit 954d9f4

Browse files
authored
Merge pull request #912 from unoplatform/dev/jela/adjust-assets
fix: don't prefix uno-assets path with the package folder for compatibility
2 parents 61861ee + fd21e87 commit 954d9f4

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

doc/features-additional-files.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Exclusions:
3939

4040
1. Files in the `WasmScript` folder will be set as `UnoDeploy="None"` by default (they are not treat as content)
4141

42-
2. Files in the `wwwroot` folder will be set as `UnoDeploy="Root"` by default
42+
1. Files in the `wwwroot` folder will be set as `UnoDeploy="Root"` by default
4343

44-
3. You can manually set the _deploy mode_ in the `.csproj` in the following way:
44+
1. You can manually set the _deploy mode_ in the `.csproj` in the following way:
4545

4646
```xml
4747
<ItemGroup>
@@ -56,6 +56,18 @@ Exclusions:
5656
</ItemGroup>
5757
```
5858

59-
Asset files: `wwwroot/uno-assets.txt` contains the package relative paths of the content files that were copied to the `wwwroot` folder. It can be used to identify which assets are packaged with the application at runtime and avoid costly probing operations. Important: Will only contain files deployed in `UnoDeploy="Package"` mode.
59+
1. A few files extensions are excluded (`UnoDeploy="None")`by default such as `*.a`, `*.o`. `.html` files are those named `web.config` will default to `UnoDeploy="Root"`.
6060

61-
A few files extensions are excluded (`UnoDeploy="None")`by default such as `*.a`, `*.o`. `.html` files are those named `web.config` will default to `UnoDeploy="Root"`.
61+
### Asset dictionary
62+
63+
The file `wwwroot/package_XXX/uno-assets.txt` contains the package relative paths of the content files that were copied to the `wwwroot` folder.
64+
65+
It can be used to identify which assets are packaged with the application at runtime and avoid costly probing operations.
66+
67+
The files are specified in two parts:
68+
69+
- The files located in the `_framework` folder, which are all the assemblies used to run the app. The path in the `uno-assets.txt` file is relative to the base uri of the site.
70+
- The files contained in `package_XXX` folder, which are the Content files specified at build time. The path in the `uno-assets.txt` file is relative to the `package_XXX` folder of the site.
71+
72+
> [!IMPORTANT]
73+
> This file only contain files deployed in `UnoDeploy="Package"` mode.

src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ public override bool Execute()
5858
foreach(var asset in StaticWebAsset)
5959
{
6060
var assetPath = Path.GetDirectoryName(asset.GetMetadata("RelativePath")) + "/" + Path.GetFileName(asset.GetMetadata("FullPath"));
61-
assets.Add(assetPath.Replace("\\", "/").TrimStart('/'));
61+
var sanitizedAssetPath = assetPath.Replace("\\", "/").TrimStart('/');
62+
63+
if (sanitizedAssetPath.StartsWith(OutputPackagePath + "/"))
64+
{
65+
// Remove the original path OutputPackagePath from the path to keep
66+
// net8 compatibility.
67+
sanitizedAssetPath = sanitizedAssetPath.Substring(OutputPackagePath.Length + 1);
68+
}
69+
70+
assets.Add(sanitizedAssetPath);
6271
}
6372

6473
var assetsFilePath = Path.Combine(_intermediateAssetsPath, "uno-assets.txt");

src/Uno.Wasm.Sample/sample.common.props

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,28 @@
4444
<ItemGroup>
4545
<ProjectReference Include="..\Uno.Wasm.Sample.Library\Uno.Wasm.Sample.Library.csproj" />
4646
</ItemGroup>
47+
48+
<Target Name="AfterPublishValidation" AfterTargets="Publish">
49+
50+
<PropertyGroup>
51+
<_appOutput>$(PublishDir)wwwroot/$(WasmShellOutputPackagePath)</_appOutput>
52+
</PropertyGroup>
53+
54+
<!-- read the contents of the file uno-assets.txt -->
55+
<ReadLinesFromFile File="$(_appOutput)/uno-assets.txt">
56+
<Output TaskParameter="Lines" ItemName="_UnoAssetsLines"/>
57+
</ReadLinesFromFile>
58+
59+
<ItemGroup>
60+
<_InvalidAssetLines Include="@(_UnoAssetsLines)"
61+
Condition="$([System.String]::Copy('%(Identity)').StartsWith('package_'))" />
62+
</ItemGroup>
63+
64+
<!-- Fail if any _UnoAssetsLines item contains the string `package_` -->
65+
<Error Condition=" '@(_InvalidAssetLines)' != ''"
66+
Text="No asset should start with 'package_'" />
67+
68+
<Message Importance="high" Text="Output dist validated" />
69+
</Target>
4770

4871
</Project>

0 commit comments

Comments
 (0)