981c48a65a7f30c94375619ca8065219fb2bf352
[platform/upstream/dotnet/runtime.git] /
1 <!--
2 ***********************************************************************************************
3 Microsoft.NET.Sdk.WebAssembly.targets
4
5 WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6           created a backup copy.  Incorrect changes to this file will make it
7           impossible to load or build your projects from the command-line or the IDE.
8
9 Copyright (c) .NET Foundation. All rights reserved.
10 ***********************************************************************************************
11 -->
12 <Project ToolsVersion="14.0">
13
14   <PropertyGroup>
15     <_UseBlazorDevServer>$(RunArguments.Contains('blazor-devserver.dll').ToString().ToLower())</_UseBlazorDevServer>
16   </PropertyGroup>
17   <PropertyGroup Condition="'$(_WebAssemblyUserRunParameters)' == '' and '$(_UseBlazorDevServer)' == 'false'">
18     <RunCommand Condition="'$(DOTNET_HOST_PATH)' != '' and Exists($(DOTNET_HOST_PATH))">$(DOTNET_HOST_PATH)</RunCommand>
19     <RunCommand Condition="'$(RunCommand)' == ''">dotnet</RunCommand>
20
21     <WasmAppHostDir>$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'WasmAppHost'))</WasmAppHostDir>
22     <_RuntimeConfigJsonPath>$([MSBuild]::NormalizePath($(OutputPath), '$(AssemblyName).runtimeconfig.json'))</_RuntimeConfigJsonPath>
23     <RunArguments>exec &quot;$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))&quot; --use-staticwebassets --runtime-config &quot;$(_RuntimeConfigJsonPath)&quot; $(WasmHostArguments)</RunArguments>
24     <RunWorkingDirectory>$(OutputPath)</RunWorkingDirectory>
25   </PropertyGroup>
26
27   <PropertyGroup>
28     <EnableDefaultContentItems Condition=" '$(EnableDefaultContentItems)' == '' ">true</EnableDefaultContentItems>
29
30     <!-- Trimmer defaults that depend on user-definable settings.
31         This must be configured before it's initialized in the .NET SDK targets (which are imported by the Razor SDK). -->
32     <SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(TrimmerDefaultAction)' != 'link'">true</SuppressTrimAnalysisWarnings>
33   </PropertyGroup>
34
35   <!--
36     Targets supporting Razor MSBuild integration. Contain support for generating C# code using Razor
37     and including the generated code in the project lifecycle, including compiling, publishing and producing
38     nuget packages.
39   -->
40
41   <PropertyGroup>
42     <!-- Paths to tools, tasks, and extensions are calculated relative to the WebAssemblySdkDirectoryRoot. This can be modified to test a local build. -->
43     <WebAssemblySdkDirectoryRoot Condition="'$(WebAssemblySdkDirectoryRoot)'==''">$(MSBuildThisFileDirectory)..\</WebAssemblySdkDirectoryRoot>
44     <_WebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net8.0</_WebAssemblySdkTasksTFM>
45     <_WebAssemblySdkTasksTFM Condition=" '$(MSBuildRuntimeType)' != 'Core'">net472</_WebAssemblySdkTasksTFM>
46     <_WebAssemblySdkTasksAssembly>$(WebAssemblySdkDirectoryRoot)tools\$(_WebAssemblySdkTasksTFM)\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.dll</_WebAssemblySdkTasksAssembly>
47
48     <!-- Compression -->
49     <CompressionIncludePatterns>$(CompressionIncludePatterns);_framework\**</CompressionIncludePatterns>
50     <DisableBuildCompression Condition="'$(WasmBuildingForNestedPublish)' == 'true'">true</DisableBuildCompression>
51   </PropertyGroup>
52
53   <UsingTask TaskName="Microsoft.NET.Sdk.WebAssembly.GenerateWasmBootJson" AssemblyFile="$(_WebAssemblySdkTasksAssembly)" />
54   <UsingTask TaskName="Microsoft.NET.Sdk.WebAssembly.ComputeWasmBuildAssets" AssemblyFile="$(_WebAssemblySdkTasksAssembly)" />
55   <UsingTask TaskName="Microsoft.NET.Sdk.WebAssembly.ComputeWasmPublishAssets" AssemblyFile="$(_WebAssemblySdkTasksAssembly)" />
56   <UsingTask TaskName="Microsoft.NET.Sdk.WebAssembly.ConvertDllsToWebCil" AssemblyFile="$(_WebAssemblySdkTasksAssembly)" />
57
58   <PropertyGroup>
59     <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
60
61     <!-- Runtime feature defaults to trim unnecessary code -->
62     <InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
63     <InvariantTimezone Condition="'$(BlazorEnableTimeZoneSupport)' == 'false'">true</InvariantTimezone>
64     <InvariantTimezone Condition="'$(InvariantTimezone)' == ''">false</InvariantTimezone>
65     <EventSourceSupport Condition="'$(EventSourceSupport)' == ''">false</EventSourceSupport>
66     <UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">true</UseSystemResourceKeys>
67     <EnableUnsafeUTF7Encoding Condition="'$(EnableUnsafeUTF7Encoding)' == ''">false</EnableUnsafeUTF7Encoding>
68     <HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport>
69     <NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">false</NullabilityInfoContextSupport>
70     <_AggressiveAttributeTrimming Condition="'$(_AggressiveAttributeTrimming)' == ''">true</_AggressiveAttributeTrimming>
71     <DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(Configuration)' != 'Debug'">false</DebuggerSupport>
72     <BlazorCacheBootResources Condition="'$(BlazorCacheBootResources)' == ''">true</BlazorCacheBootResources>
73     <WasmFingerprintDotnetJs Condition="'$(WasmFingerprintDotnetJs)' == ''">false</WasmFingerprintDotnetJs>
74
75     <!-- Turn off parts of the build that do not apply to WASM projects -->
76     <GenerateDependencyFile>false</GenerateDependencyFile>
77     <PreserveCompilationContext>false</PreserveCompilationContext>
78     <PreserveCompilationReferences>false</PreserveCompilationReferences>
79     <IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
80
81     <!-- JS Modules -->
82     <!-- We disable the manifest generation because we are going to inline the modules in the blazor.boot.json manifest -->
83     <GenerateJSModuleManifest>false</GenerateJSModuleManifest>
84
85     <EnableDefaultWasmAssembliesToBundle>false</EnableDefaultWasmAssembliesToBundle>
86     <WasmNestedPublishAppDependsOn>_GatherWasmFilesToPublish;$(WasmNestedPublishAppDependsOn)</WasmNestedPublishAppDependsOn>
87     <_WasmNestedPublishAppPreTarget>ComputeFilesToPublish</_WasmNestedPublishAppPreTarget>
88   </PropertyGroup>
89
90   <ItemGroup>
91     <!-- Configuration for the platform compatibility analyzer. See https://github.com/dotnet/designs/blob/main/accepted/2020/platform-exclusion/platform-exclusion.md#build-configuration-for-platforms -->
92     <SupportedPlatform Remove="@(SupportedPlatform)" />
93     <SupportedPlatform Include="browser" />
94   </ItemGroup>
95
96   <!-- Wire-up static web assets -->
97   <PropertyGroup>
98     <!-- Static Web Assets -->
99     <ResolveStaticWebAssetsInputsDependsOn>
100       $(ResolveStaticWebAssetsInputsDependsOn);
101       _AddWasmStaticWebAssets;
102     </ResolveStaticWebAssetsInputsDependsOn>
103     <StaticWebAssetsPrepareForRunDependsOn>
104       _GenerateBuildWasmBootJson;
105       $(StaticWebAssetsPrepareForRunDependsOn)
106     </StaticWebAssetsPrepareForRunDependsOn>
107     <ResolvePublishStaticWebAssetsDependsOn Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
108       $(ResolvePublishStaticWebAssetsDependsOn);
109       ProcessPublishFilesForWasm;
110       ComputeWasmExtensions;
111       _AddPublishWasmBootJsonToStaticWebAssets;
112     </ResolvePublishStaticWebAssetsDependsOn>
113     <GenerateStaticWebAssetsPublishManifestDependsOn Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
114       $(GenerateStaticWebAssetsPublishManifestDependsOn);
115       GeneratePublishWasmBootJson;
116     </GenerateStaticWebAssetsPublishManifestDependsOn>
117
118     <!-- Compression -->
119     <ResolveCompressedFilesDependsOn>
120       $(ResolveCompressedFilesDependsOn);
121       ResolveWasmOutputs;
122       _AddWasmStaticWebAssets;
123     </ResolveCompressedFilesDependsOn>
124     <ResolveCompressedFilesForPublishDependsOn>
125       $(ResolveCompressedFilesForPublishDependsOn);
126       ProcessPublishFilesForWasm;
127       ComputeWasmExtensions;
128       _AddPublishWasmBootJsonToStaticWebAssets;
129     </ResolveCompressedFilesForPublishDependsOn>
130     <CompressFilesDependsOn>
131       $(CompressFilesDependsOn)
132       _GenerateBuildWasmBootJson;
133     </CompressFilesDependsOn>
134     <CompressFilesForPublishDependsOn>
135       $(CompressFilesForPublishDependsOn);
136       GeneratePublishWasmBootJson;
137     </CompressFilesForPublishDependsOn>
138
139     <!-- Wasm -->
140     <AddWasmStaticWebAssetsDependsOn>
141       $(AddWasmStaticWebAssetsDependsOn);
142       ResolveWasmOutputs;
143     </AddWasmStaticWebAssetsDependsOn>
144     <GenerateBuildWasmBootJsonDependsOn>
145       $(GenerateBuildWasmBootJsonDependsOn);
146       ResolveStaticWebAssetsInputs;
147     </GenerateBuildWasmBootJsonDependsOn>
148     <GeneratePublishWasmBootJsonDependsOn>
149       $(GeneratePublishWasmBootJsonDependsOn);
150     </GeneratePublishWasmBootJsonDependsOn>
151   </PropertyGroup>
152
153   <Target Name="_WasmNativeForBuild" DependsOnTargets="_GatherWasmFilesToBuild;WasmBuildApp" Condition="'$(UsingBrowserRuntimeWorkload)' == 'true'" />
154
155   <Target Name="_GatherWasmFilesToBuild">
156     <ItemGroup>
157       <WasmAssembliesToBundle Remove="@(WasmAssembliesToBundle)" />
158       <WasmAssembliesToBundle Include="@(IntermediateAssembly)" />
159       <WasmAssembliesToBundle Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'" />
160     </ItemGroup>
161   </Target>
162
163   <Target Name="_ResolveGlobalizationConfiguration">
164     <Error Condition="'$(BlazorIcuDataFileName)' != '' AND !$([System.IO.Path]::GetFileName('$(BlazorIcuDataFileName)').StartsWith('icudt'))" Text="File name in %24(BlazorIcuDataFileName) has to start with 'icudt'." />
165     <Warning Condition="'$(InvariantGlobalization)' == 'true' AND '$(BlazorWebAssemblyLoadAllGlobalizationData)' == 'true'" Text="%24(BlazorWebAssemblyLoadAllGlobalizationData) has no effect when %24(InvariantGlobalization) is set to true." />
166     <Warning Condition="'$(HybridGlobalization)' == 'true' AND '$(BlazorWebAssemblyLoadAllGlobalizationData)' == 'true'" Text="%24(BlazorWebAssemblyLoadAllGlobalizationData) has no effect when %24(HybridGlobalization) is set to true." />
167     <Warning Condition="'$(InvariantGlobalization)' == 'true' AND '$(BlazorIcuDataFileName)' != ''" Text="%24(BlazorIcuDataFileName) has no effect when %24(InvariantGlobalization) is set to true." />
168     <Warning Condition="'$(BlazorWebAssemblyLoadAllGlobalizationData)' == 'true' AND '$(BlazorIcuDataFileName)' != ''" Text="%24(BlazorIcuDataFileName) has no effect when %24(BlazorWebAssemblyLoadAllGlobalizationData) is set to true." />
169     <Warning Condition="'$(InvariantGlobalization)' == 'true' AND '$(HybridGlobalization)' == 'true'" Text="%24(HybridGlobalization) has no effect when %24(InvariantGlobalization) is set to true." />
170     <Warning Condition="'$(BlazorIcuDataFileName)' != '' AND '$(HybridGlobalization)' == 'true'" Text="%24(HybridGlobalization) has no effect when %24(BlazorIcuDataFileName) is set." />
171     <PropertyGroup>
172       <HybridGlobalization Condition="'$(BlazorIcuDataFileName)' != ''">false</HybridGlobalization>
173       <_BlazorWebAssemblyLoadAllGlobalizationData Condition="'$(InvariantGlobalization)' != 'true' AND '$(HybridGlobalization)' != 'true'">$(BlazorWebAssemblyLoadAllGlobalizationData)</_BlazorWebAssemblyLoadAllGlobalizationData>
174       <_BlazorWebAssemblyLoadAllGlobalizationData Condition="'$(_BlazorWebAssemblyLoadAllGlobalizationData)' == ''">false</_BlazorWebAssemblyLoadAllGlobalizationData>
175       <_IsHybridGlobalization>$(HybridGlobalization)</_IsHybridGlobalization>
176       <_IsHybridGlobalization Condition="'$(InvariantGlobalization)' == 'true' OR '$(HybridGlobalization)' == ''">false</_IsHybridGlobalization>
177       <_BlazorIcuDataFileName Condition="'$(InvariantGlobalization)' != 'true' AND '$(BlazorWebAssemblyLoadAllGlobalizationData)' != 'true' AND '$(HybridGlobalization)' != 'true'">$(BlazorIcuDataFileName)</_BlazorIcuDataFileName>
178       <_LoadCustomIcuData>false</_LoadCustomIcuData>
179       <_LoadCustomIcuData Condition="'$(_BlazorIcuDataFileName)' != ''">true</_LoadCustomIcuData>
180     </PropertyGroup>
181   </Target>
182
183   <Target Name="_ResolveWasmConfiguration" DependsOnTargets="_ResolveGlobalizationConfiguration">
184     <PropertyGroup>
185       <_TargetingNET80OrLater>false</_TargetingNET80OrLater>
186       <_TargetingNET80OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '8.0'))">true</_TargetingNET80OrLater>
187
188       <_BlazorEnableTimeZoneSupport>$(BlazorEnableTimeZoneSupport)</_BlazorEnableTimeZoneSupport>
189       <_BlazorEnableTimeZoneSupport Condition="'$(_BlazorEnableTimeZoneSupport)' == ''">true</_BlazorEnableTimeZoneSupport>
190       <_WasmInvariantGlobalization>$(InvariantGlobalization)</_WasmInvariantGlobalization>
191       <_WasmInvariantGlobalization Condition="'$(_WasmInvariantGlobalization)' == ''">true</_WasmInvariantGlobalization>
192       <_WasmCopyOutputSymbolsToOutputDirectory>$(CopyOutputSymbolsToOutputDirectory)</_WasmCopyOutputSymbolsToOutputDirectory>
193       <_WasmCopyOutputSymbolsToOutputDirectory Condition="'$(_WasmCopyOutputSymbolsToOutputDirectory)'==''">true</_WasmCopyOutputSymbolsToOutputDirectory>
194       <_WasmEnableThreads>$(WasmEnableThreads)</_WasmEnableThreads>
195       <_WasmEnableThreads Condition="'$(_WasmEnableThreads)' == ''">false</_WasmEnableThreads>
196
197       <_WasmEnableWebcil>$(WasmEnableWebcil)</_WasmEnableWebcil>
198       <_WasmEnableWebcil Condition="'$(_TargetingNET80OrLater)' != 'true'">false</_WasmEnableWebcil>
199       <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">true</_WasmEnableWebcil>
200       <_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache)</_BlazorWebAssemblyStartupMemoryCache>
201       <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter)</_BlazorWebAssemblyJiterpreter>
202       <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions)</_BlazorWebAssemblyRuntimeOptions>
203       <_WasmDebugLevel>$(WasmDebugLevel)</_WasmDebugLevel>
204       <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0</_WasmDebugLevel>
205       <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == '0' and ('$(DebuggerSupport)' == 'true' or '$(Configuration)' == 'Debug')">-1</_WasmDebugLevel>
206
207       <!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
208       <PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
209     </PropertyGroup>
210   </Target>
211
212   <Target Name="ResolveWasmOutputs" DependsOnTargets="_ResolveWasmOutputs" />
213
214   <Target Name="_GetWasmRuntimePackVersion">
215     <PropertyGroup>
216       <_WasmRuntimePackVersion>%(ResolvedRuntimePack.NuGetPackageVersion)</_WasmRuntimePackVersion>
217     </PropertyGroup>
218
219     <Error Code="WASM0005" Message="Unnable to resolve WebAssembly runtime pack version" Condition="'$(_WasmRuntimePackVersion)' == ''" />
220   </Target>
221
222   <Target Name="_ResolveWasmOutputs" DependsOnTargets="ResolveReferences;PrepareResourceNames;ComputeIntermediateSatelliteAssemblies;_ResolveWasmConfiguration;_WasmNativeForBuild;_GetWasmRuntimePackVersion">
223     <ItemGroup>
224       <_WasmConfigFileCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" />
225
226       <!-- Remove dotnet.js/wasm from runtime pack, in favor of the relinked ones in @(WasmNativeAsset) -->
227       <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)"
228                                Condition="@(WasmNativeAsset->Count()) > 0 and ( '%(FileName)' == 'dotnet' or '%(FileName)' == 'dotnet.native' ) and ('%(Extension)' == '.wasm' or '%(Extension)' == '.js')" />
229     </ItemGroup>
230
231     <PropertyGroup>
232       <_WasmEmitSourceMapBuild>$(WasmEmitSourceMap)</_WasmEmitSourceMapBuild>
233       <_WasmEmitSourceMapBuild Condition="'$(_WasmEmitSourceMapBuild)' == ''">true</_WasmEmitSourceMapBuild>
234     </PropertyGroup>
235
236     <ComputeWasmBuildAssets
237       Candidates="@(ReferenceCopyLocalPaths->Distinct());@(WasmNativeAsset)"
238       CustomIcuCandidate="$(_BlazorIcuDataFileName)"
239       ProjectAssembly="@(IntermediateAssembly)"
240       ProjectDebugSymbols="@(_DebugSymbolsIntermediatePath)"
241       SatelliteAssemblies="@(ReferenceSatellitePaths)"
242       ProjectSatelliteAssemblies="@(IntermediateSatelliteAssembliesWithTargetPath)"
243       TimeZoneSupport="$(_BlazorEnableTimeZoneSupport)"
244       InvariantGlobalization="$(_WasmInvariantGlobalization)"
245       HybridGlobalization="$(_IsHybridGlobalization)"
246       LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
247       DotNetJsVersion="$(_WasmRuntimePackVersion)"
248       CopySymbols="$(_WasmCopyOutputSymbolsToOutputDirectory)"
249       OutputPath="$(OutputPath)"
250       FingerprintDotNetJs="$(WasmFingerprintDotnetJs)"
251       EnableThreads="$(_WasmEnableThreads)"
252       EmitSourceMap="$(_WasmEmitSourceMapBuild)"
253     >
254       <Output TaskParameter="AssetCandidates" ItemName="_BuildAssetsCandidates" />
255       <Output TaskParameter="FilesToRemove" ItemName="_WasmBuildFilesToRemove" />
256     </ComputeWasmBuildAssets>
257
258     <PropertyGroup>
259       <_WasmBuildWebCilPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'webcil'))</_WasmBuildWebCilPath>
260       <_WasmBuildTmpWebCilPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'tmp-webcil'))</_WasmBuildTmpWebCilPath>
261     </PropertyGroup>
262
263     <ConvertDllsToWebCil Candidates="@(_BuildAssetsCandidates)" IntermediateOutputPath="$(_WasmBuildTmpWebCilPath)" OutputPath="$(_WasmBuildWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
264       <Output TaskParameter="WebCilCandidates" ItemName="_WebCilAssetsCandidates" />
265       <Output TaskParameter="FileWrites" ItemName="FileWrites" />
266     </ConvertDllsToWebCil>
267
268     <DefineStaticWebAssets
269       CandidateAssets="@(_WebCilAssetsCandidates)"
270       SourceId="$(PackageId)"
271       SourceType="Computed"
272       AssetKind="Build"
273       AssetRole="Primary"
274       CopyToOutputDirectory="PreserveNewest"
275       CopyToPublishDirectory="Never"
276       ContentRoot="$(OutputPath)wwwroot"
277       BasePath="$(StaticWebAssetBasePath)"
278     >
279       <Output TaskParameter="Assets" ItemName="WasmStaticWebAsset" />
280     </DefineStaticWebAssets>
281
282     <DefineStaticWebAssets
283       CandidateAssets="@(_WasmConfigFileCandidates)"
284       AssetTraitName="WasmResource"
285       AssetTraitValue="settings"
286       RelativePathFilter="appsettings*.json"
287     >
288       <Output TaskParameter="Assets" ItemName="_WasmJsConfigStaticWebAsset" />
289     </DefineStaticWebAssets>
290
291     <ItemGroup>
292       <!-- Update the boot config static web asset since we've given it a trait -->
293       <StaticWebAsset Remove="@(_WasmJsConfigStaticWebAsset)" />
294       <StaticWebAsset Include="@(_WasmJsConfigStaticWebAsset)" />
295
296       <ReferenceCopyLocalPaths Remove="@(_WasmBuildFilesToRemove)" />
297     </ItemGroup>
298
299     <PropertyGroup>
300       <_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
301     </PropertyGroup>
302
303     <ItemGroup>
304       <_BuildWasmBootJson
305         Include="$(_WasmBuildBootJsonPath)"
306         RelativePath="_framework/blazor.boot.json" />
307     </ItemGroup>
308
309     <DefineStaticWebAssets
310       CandidateAssets="@(_BuildWasmBootJson)"
311       SourceId="$(PackageId)"
312       SourceType="Computed"
313       AssetKind="Build"
314       AssetRole="Primary"
315       AssetTraitName="WasmResource"
316       AssetTraitValue="manifest"
317       CopyToOutputDirectory="PreserveNewest"
318       CopyToPublishDirectory="Never"
319       ContentRoot="$(OutDir)wwwroot"
320       BasePath="$(StaticWebAssetBasePath)"
321     >
322       <Output TaskParameter="Assets" ItemName="_BuildWasmBootJsonStaticWebAsset" />
323     </DefineStaticWebAssets>
324   </Target>
325
326   <Target Name="_AddWasmStaticWebAssets" DependsOnTargets="$(AddWasmStaticWebAssetsDependsOn)">
327     <ItemGroup>
328       <StaticWebAsset Include="@(WasmStaticWebAsset)" />
329       <StaticWebAsset Include="@(_BuildWasmBootJsonStaticWebAsset)" />
330     </ItemGroup>
331   </Target>
332
333   <Target Name="_GenerateBuildWasmBootJson" DependsOnTargets="$(GenerateBuildWasmBootJsonDependsOn)">
334     <PropertyGroup>
335       <_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
336     </PropertyGroup>
337
338     <ItemGroup>
339       <_WasmJsModuleCandidatesForBuild
340         Include="@(StaticWebAsset)"
341         Condition="'%(StaticWebAsset.AssetTraitName)' == 'JSModule' and '%(StaticWebAsset.AssetTraitValue)' == 'JSLibraryModule' and '%(AssetKind)' != 'Publish'" />
342     </ItemGroup>
343
344     <GetFileHash Files="@(WasmStaticWebAsset->'%(OriginalItemSpec)')" Algorithm="SHA256" HashEncoding="base64">
345       <Output TaskParameter="Items" ItemName="_WasmOutputWithHash" />
346     </GetFileHash>
347
348     <ComputeStaticWebAssetsTargetPaths
349       Assets="@(_WasmJsModuleCandidatesForBuild)"
350       PathPrefix=""
351       UseAlternatePathDirectorySeparator="true"
352     >
353       <Output TaskParameter="AssetsWithTargetPath" ItemName="_WasmJsModuleCandidatesForBuildWithTargetPath" />
354     </ComputeStaticWebAssetsTargetPaths>
355
356     <GetFileHash Files="@(_WasmJsModuleCandidatesForBuildWithTargetPath)" Algorithm="SHA256" HashEncoding="base64">
357       <Output TaskParameter="Items" ItemName="_WasmOutputWithHash" />
358     </GetFileHash>
359
360     <GenerateWasmBootJson
361       AssemblyPath="@(IntermediateAssembly)"
362       Resources="@(_WasmOutputWithHash)"
363       DebugBuild="true"
364       DebugLevel="$(_WasmDebugLevel)"
365       LinkerEnabled="false"
366       CacheBootResources="$(BlazorCacheBootResources)"
367       OutputPath="$(_WasmBuildBootJsonPath)"
368       ConfigurationFiles="@(_WasmJsConfigStaticWebAsset)"
369       LazyLoadedAssemblies="@(BlazorWebAssemblyLazyLoad)"
370       InvariantGlobalization="$(InvariantGlobalization)"
371       LoadCustomIcuData="$(_LoadCustomIcuData)"
372       IsHybridGlobalization="$(_IsHybridGlobalization)"
373       LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
374       StartupMemoryCache="$(_BlazorWebAssemblyStartupMemoryCache)"
375       Jiterpreter="$(_BlazorWebAssemblyJiterpreter)"
376       RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
377       Extensions="@(WasmBootConfigExtension)"
378       TargetFrameworkVersion="$(TargetFrameworkVersion)"
379       ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
380       ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />
381
382     <ItemGroup>
383       <FileWrites Include="$(_WasmBuildBootJsonPath)" />
384     </ItemGroup>
385   </Target>
386
387   <!-- Publish starts here -->
388
389   <!-- Make sure that ResolveAssemblyReferences runs early enough to ensure satellite assemblies are populated in the ResolvedFilesToPublish -->
390   <Target Name="_WasmPrepareForPublish"
391     DependsOnTargets="PrepareResourceNames;ComputeIntermediateSatelliteAssemblies;ResolveAssemblyReferences"
392     BeforeTargets="PrepareForPublish" />
393
394   <!-- Wasm's Nested publish is run just to build the native bits. We don't need to run blazor targets for that -->
395   <Target Name="ProcessPublishFilesForWasm" DependsOnTargets="_ResolveWasmConfiguration;LoadStaticWebAssetsBuildManifest;_GetWasmRuntimePackVersion" AfterTargets="ILLink" Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
396     <!-- The list of static web assets already contains all the assets from the build. We want to correct certain assets that might
397          have changed as part of the publish process. We are going to do so as follows:
398          * We will update Blazor runtime asset dlls if we are running PublishTrimmed
399          * We will update Blazor native runtime resources if we are using Aot
400          Other than that, we'll filter the unwanted assets from the list of resolved files to publish in the same way we did during the build.
401     -->
402
403     <ItemGroup>
404       <_WasmPublishPrefilteredAssets
405         Include="@(StaticWebAsset)"
406         Condition="'%(StaticWebAsset.AssetTraitName)' == 'WasmResource' or '%(StaticWebAsset.AssetTraitName)' == 'Culture' or '%(AssetRole)' == 'Alternative'" />
407     </ItemGroup>
408
409     <PropertyGroup>
410       <_WasmEmitSourceMapPublish>$(WasmEmitSourceMap)</_WasmEmitSourceMapPublish>
411       <_WasmEmitSourceMapPublish Condition="'$(_WasmEmitSourceMapPublish)' == ''">false</_WasmEmitSourceMapPublish>
412     </PropertyGroup>
413
414     <ComputeWasmPublishAssets
415       ResolvedFilesToPublish="@(ResolvedFileToPublish)"
416       CustomIcuCandidate="$(_BlazorIcuDataFileName)"
417       TimeZoneSupport="$(_BlazorEnableTimeZoneSupport)"
418       PublishPath="$(PublishDir)"
419       WasmAotAssets="@(WasmNativeAsset)"
420       InvariantGlobalization="$(_WasmInvariantGlobalization)"
421       HybridGlobalization="$(_IsHybridGlobalization)"
422       LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
423       CopySymbols="$(CopyOutputSymbolsToPublishDirectory)"
424       ExistingAssets="@(_WasmPublishPrefilteredAssets)"
425       DotNetJsVersion="$(_WasmRuntimePackVersion)"
426       FingerprintDotNetJs="$(WasmFingerprintDotnetJs)"
427       EnableThreads="$(_WasmEnableThreads)"
428       EmitSourceMap="$(_WasmEmitSourceMapPublish)"
429       IsWebCilEnabled="$(_WasmEnableWebcil)"
430     >
431       <Output TaskParameter="NewCandidates" ItemName="_NewWasmPublishStaticWebAssets" />
432       <Output TaskParameter="FilesToRemove" ItemName="_PublishResolvedFilesToRemove" />
433     </ComputeWasmPublishAssets>
434
435     <PropertyGroup>
436       <_WasmPublishWebCilPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'webcil', 'publish'))</_WasmPublishWebCilPath>
437       <_WasmPublishTmpWebCilPath>$([MSBuild]::NormalizeDirectory($(IntermediateOutputPath), 'tmp-webcil', 'publish'))</_WasmPublishTmpWebCilPath>
438     </PropertyGroup>
439
440     <ConvertDllsToWebCil Candidates="@(_NewWasmPublishStaticWebAssets)" IntermediateOutputPath="$(_WasmPublishTmpWebCilPath)" OutputPath="$(_WasmPublishWebCilPath)" IsEnabled="$(_WasmEnableWebcil)">
441       <Output TaskParameter="WebCilCandidates" ItemName="_NewWebCilPublishStaticWebAssets" />
442       <Output TaskParameter="FileWrites" ItemName="FileWrites" />
443     </ConvertDllsToWebCil>
444
445     <ItemGroup>
446       <ResolvedFileToPublish Remove="@(_PublishResolvedFilesToRemove)" />
447       <StaticWebAsset Include="@(_NewWebCilPublishStaticWebAssets)" />
448
449       <!-- TODO: Probably doesn't do anything as of now, original https://github.com/dotnet/aspnetcore/pull/34798 -->
450       <PublishBlazorBootStaticWebAsset
451         Include="@(StaticWebAsset)"
452         Condition="'%(AssetKind)' != 'Build' and
453                     (('%(StaticWebAsset.AssetTraitName)' == 'WasmResource' and '%(StaticWebAsset.AssetTraitValue)' != 'manifest' and '%(StaticWebAsset.AssetTraitValue)' != 'boot') or
454                     '%(StaticWebAsset.AssetTraitName)' == 'Culture')" />
455     </ItemGroup>
456   </Target>
457
458   <Target
459     Name="ComputeWasmExtensions"
460     AfterTargets="ProcessPublishFilesForWasm"
461     DependsOnTargets="$(ComputeBlazorExtensionsDependsOn)" >
462     <ItemGroup>
463       <_BlazorExtensionsCandidate Include="@(BlazorPublishExtension->'%(FullPath)')">
464         <SourceId>$(PackageId)</SourceId>
465         <SourceType>Computed</SourceType>
466         <ContentRoot>$(PublishDir)wwwroot</ContentRoot>
467         <BasePath>$(StaticWebAssetBasePath)</BasePath>
468         <RelativePath>%(BlazorPublishExtension.RelativePath)</RelativePath>
469         <AssetKind>Publish</AssetKind>
470         <AssetMode>All</AssetMode>
471         <AssetRole>Primary</AssetRole>
472         <AssetTraitName>WasmResource</AssetTraitName>
473         <AssetTraitValue>extension:%(BlazorPublishExtension.ExtensionName)</AssetTraitValue>
474         <CopyToOutputDirectory>Never</CopyToOutputDirectory>
475         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
476         <OriginalItemSpec>%(BlazorPublishExtension.Identity)</OriginalItemSpec>
477       </_BlazorExtensionsCandidate>
478     </ItemGroup>
479
480     <DefineStaticWebAssets CandidateAssets="@(_BlazorExtensionsCandidate)">
481       <Output TaskParameter="Assets" ItemName="StaticWebAsset" />
482       <Output TaskParameter="Assets" ItemName="_BlazorExtensionsCandidatesForPublish" />
483       <Output TaskParameter="Assets" ItemName="AssetToCompress" />
484     </DefineStaticWebAssets>
485   </Target>
486
487   <Target Name="_AddWasmWebConfigFile" AfterTargets="ILLink">
488     <ItemGroup Condition="'@(ResolvedFileToPublish->AnyHaveMetadataValue('RelativePath', 'web.config'))' != 'true'">
489       <ResolvedFileToPublish
490          Include="$(MSBuildThisFileDirectory)Wasm.web.config"
491          ExcludeFromSingleFile="true"
492          CopyToPublishDirectory="PreserveNewest"
493          RelativePath="web.config" />
494     </ItemGroup>
495   </Target>
496
497   <Target Name="_AddPublishWasmBootJsonToStaticWebAssets">
498     <ItemGroup>
499       <_PublishWasmBootJson
500         Include="$(IntermediateOutputPath)blazor.publish.boot.json"
501         RelativePath="_framework/blazor.boot.json" />
502     </ItemGroup>
503
504     <DefineStaticWebAssets
505       CandidateAssets="@(_PublishWasmBootJson)"
506       SourceId="$(PackageId)"
507       SourceType="Computed"
508       AssetKind="Publish"
509       AssetRole="Primary"
510       AssetTraitName="WasmResource"
511       AssetTraitValue="manifest"
512       CopyToOutputDirectory="Never"
513       CopyToPublishDirectory="PreserveNewest"
514       ContentRoot="$(PublishDir)wwwroot"
515       BasePath="$(StaticWebAssetBasePath)"
516     >
517       <Output TaskParameter="Assets" ItemName="StaticWebAsset" />
518     </DefineStaticWebAssets>
519   </Target>
520
521   <Target Name="GeneratePublishWasmBootJson" DependsOnTargets="$(GeneratePublishWasmBootJsonDependsOn)">
522
523     <ItemGroup>
524       <_WasmPublishAsset
525         Include="@(StaticWebAsset)"
526         Condition="'%(AssetKind)' != 'Build' and '%(StaticWebAsset.AssetTraitValue)' != 'manifest' and ('%(StaticWebAsset.AssetTraitName)' == 'WasmResource' or '%(StaticWebAsset.AssetTraitName)' == 'Culture') and '%(StaticWebAsset.AssetTraitValue)' != 'boot'" />
527
528       <_WasmPublishConfigFile
529         Include="@(StaticWebAsset)"
530         Condition="'%(StaticWebAsset.AssetTraitName)' == 'WasmResource' and '%(StaticWebAsset.AssetTraitValue)' == 'settings'"/>
531
532       <_WasmJsModuleCandidatesForPublish
533         Include="@(StaticWebAsset)"
534         Condition="'%(StaticWebAsset.AssetTraitName)' == 'JSModule' and '%(StaticWebAsset.AssetTraitValue)' == 'JSLibraryModule' and '%(AssetKind)' != 'Build'" />
535
536       <!-- We remove the extensions since they are added to the list of static web assets but we need to compute the target path for them -->
537       <_WasmPublishAsset Remove="@(_BlazorExtensionsCandidatesForPublish)" />
538
539     </ItemGroup>
540
541     <ComputeStaticWebAssetsTargetPaths
542       Assets="@(_WasmJsModuleCandidatesForPublish);@(_BlazorExtensionsCandidatesForPublish)"
543       PathPrefix=""
544       UseAlternatePathDirectorySeparator="true"
545     >
546       <Output TaskParameter="AssetsWithTargetPath" ItemName="_WasmCandidatesForPublishWithTargetPath" />
547     </ComputeStaticWebAssetsTargetPaths>
548
549     <GetFileHash Files="@(_WasmPublishAsset);@(_WasmCandidatesForPublishWithTargetPath)" Algorithm="SHA256" HashEncoding="base64">
550       <Output TaskParameter="Items" ItemName="_WasmPublishBootResourceWithHash" />
551     </GetFileHash>
552
553     <GenerateWasmBootJson
554       AssemblyPath="@(IntermediateAssembly)"
555       Resources="@(_WasmPublishBootResourceWithHash)"
556       DebugBuild="false"
557       DebugLevel="$(_WasmDebugLevel)"
558       LinkerEnabled="$(PublishTrimmed)"
559       CacheBootResources="$(BlazorCacheBootResources)"
560       OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json"
561       ConfigurationFiles="@(_WasmPublishConfigFile)"
562       LazyLoadedAssemblies="@(BlazorWebAssemblyLazyLoad)"
563       InvariantGlobalization="$(InvariantGlobalization)"
564       LoadCustomIcuData="$(_LoadCustomIcuData)"
565       IsHybridGlobalization="$(_IsHybridGlobalization)"
566       LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
567       StartupMemoryCache="$(_BlazorWebAssemblyStartupMemoryCache)"
568       Jiterpreter="$(_BlazorWebAssemblyJiterpreter)"
569       RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
570       Extensions="@(WasmBootConfigExtension)"
571       TargetFrameworkVersion="$(TargetFrameworkVersion)"
572       ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
573       ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" />
574
575     <ItemGroup>
576       <FileWrites Include="$(IntermediateOutputPath)blazor.publish.boot.json" />
577     </ItemGroup>
578
579   </Target>
580
581   <Target Name="_WasmNative"
582       DependsOnTargets="_EnsureWasmRuntimeWorkload;WasmTriggerPublishApp"
583       BeforeTargets="ProcessPublishFilesForWasm"
584       Condition="'$(UsingBrowserRuntimeWorkload)' == 'true'" />
585
586   <Target Name="_EnsureWasmRuntimeWorkload" Condition="'$(UsingBlazorAOTWorkloadManifest)' != 'true'">
587     <Error
588       Text="Publishing with AOT enabled requires the .NET WebAssembly AOT workload to be installed. To learn more, visit https://aka.ms/AAb4uzl."
589       Code="BLAZORSDK1002" />
590   </Target>
591
592   <Target Name="_GatherWasmFilesToPublish">
593     <ItemGroup>
594       <WasmAssembliesToBundle Remove="@(WasmAssembliesToBundle)" />
595       <WasmAssembliesToBundle Include="%(ResolvedFileToPublish.FullPath)" Exclude="@(_Exclude)" Condition="%(Extension) == '.dll'" />
596     </ItemGroup>
597   </Target>
598 </Project>