Skip to content

Commit 5bb7e6c

Browse files
committed
Add back compat changes
1 parent d9244e4 commit 5bb7e6c

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.5_0.targets

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ Copyright (c) .NET Foundation. All rights reserved.
267267
_BlazorWasmReplaceBundle;
268268
_BlazorWasmPrepareForRun;
269269
</GetCurrentProjectStaticWebAssetsDependsOn>
270+
271+
<GetCurrentProjectStaticWebAssetsV2DependsOn>
272+
$(GetCurrentProjectStaticWebAssetsV2DependsOn);
273+
_UpdateBlazorWasmStaticWebAssetsForV2;
274+
</GetCurrentProjectStaticWebAssetsV2DependsOn>
270275
</PropertyGroup>
271276

272277
<Target Name="_BlazorWasmReplaceBundle">
@@ -276,6 +281,20 @@ Copyright (c) .NET Foundation. All rights reserved.
276281
</ItemGroup>
277282
</Target>
278283

284+
<Target Name="_UpdateBlazorWasmStaticWebAssetsForV2" DependsOnTargets="GetCurrentProjectStaticWebAssets">
285+
<ItemGroup>
286+
<_CurrentWasmProjectStaticWebAssets Include="@(_ThisProjectStaticWebAssets)" Condition="'%(SourceId)' == '$(PackageId)'" />
287+
<_CurrentWasmProjectStaticWebAssets>
288+
<!-- We set the asset kind explicitly to build becasue blazor before 6.0 did its own publishing and was
289+
not fully integrated with static web assets, so we let it be even when called from 6.0 targets
290+
-->
291+
<AssetKind>Build</AssetKind>
292+
</_CurrentWasmProjectStaticWebAssets>
293+
<_ThisProjectStaticWebAssets Remove="@(_CurrentWasmProjectStaticWebAssets)" />
294+
<_ThisProjectStaticWebAssets Include="@(_CurrentWasmProjectStaticWebAssets)" />
295+
</ItemGroup>
296+
</Target>
297+
279298
<Target Name="_BlazorWasmPrepareForRun" DependsOnTargets="_ProcessBlazorWasmOutputs" BeforeTargets="_RazorPrepareForRun" AfterTargets="GetCurrentProjectStaticWebAssets">
280299
<PropertyGroup>
281300
<_BlazorBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_BlazorBuildBootJsonPath>

src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.ScopedCss.5_0.targets

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ Integration with static web assets:
9898
_AddGeneratedScopedCssFilesForReference;
9999
</GenerateStaticWebAssetsPackTargetsDependsOn>
100100

101+
<GetCurrentProjectStaticWebAssetsV2DependsOn>
102+
$(GetCurrentProjectStaticWebAssetsV2DependsOn);
103+
_UpdateScopedCssStaticWebAssetsForV2;
104+
</GetCurrentProjectStaticWebAssetsV2DependsOn>
105+
101106
<!-- We are going to use .rz.scp.css as the extension to mark scoped css files that come from packages or that have been pre-procesed by
102107
referenced class libraries. This way, we can use that information to adjust the build pipeline without having to rely on external
103108
sources like an additional itemgroup or metadata.
@@ -390,4 +395,43 @@ Integration with static web assets:
390395
</ItemGroup>
391396
</Target>
392397

398+
<!-- Forward compat with new static web assets -->
399+
400+
<Target Name="_UpdateScopedCssStaticWebAssetsForV2">
401+
<PropertyGroup>
402+
<_AppBundleStaticWebAssetIdentity>@(_AppBundleStaticWebAsset)</_AppBundleStaticWebAssetIdentity>
403+
<_ProjectBundleStaticWebAssetIdentity>@(_ProjectBundleStaticWebAsset)</_ProjectBundleStaticWebAssetIdentity>
404+
</PropertyGroup>
405+
406+
<ItemGroup>
407+
<!-- <<App>>.bundle.scp.css -->
408+
<_CurrentProjectBundle Include="@(_ThisProjectStaticWebAssets)" Condition="'%(SourceId)' == '$(PackageId)' and '%(_ThisProjectStaticWebAssets.Identity)' == '$(_ProjectBundleStaticWebAssetIdentity)'">
409+
<AssetMode>Reference</AssetMode>
410+
<AssetRole>Primary</AssetRole>
411+
<RelatedAsset></RelatedAsset>
412+
<AssetTraitName>ScopedCss</AssetTraitName>
413+
<AssetTraitValue>ProjectBundle</AssetTraitValue>
414+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
415+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
416+
</_CurrentProjectBundle>
417+
418+
<_ThisProjectStaticWebAssets Remove="@(_CurrentProjectBundle)" />
419+
<_ThisProjectStaticWebAssets Include="@(_CurrentProjectBundle)" />
420+
421+
<!-- <<App>>.styles.css -->
422+
<_CurrentProjectAppBundle Include="@(_ThisProjectStaticWebAssets)" Condition="'%(SourceId)' == '$(PackageId)' and '%(Identity)' == '$(_AppBundleStaticWebAssetIdentity)'">
423+
<AssetMode>CurrentProject</AssetMode>
424+
<AssetRole>Primary</AssetRole>
425+
<RelatedAsset></RelatedAsset>
426+
<AssetTraitName>ScopedCss</AssetTraitName>
427+
<AssetTraitValue>ApplicationBundle</AssetTraitValue>
428+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
429+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
430+
</_CurrentProjectAppBundle>
431+
432+
<_ThisProjectStaticWebAssets Remove="@(_CurrentProjectAppBundle)" />
433+
<_ThisProjectStaticWebAssets Include="@(_CurrentProjectAppBundle)" />
434+
</ItemGroup>
435+
</Target>
436+
393437
</Project>

src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.StaticWebAssets.5_0.targets

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,70 @@ Copyright (c) .NET Foundation. All rights reserved.
349349

350350
</Target>
351351

352+
<!--
353+
Forward compatibility with new version of static web assets. This target is invoked by later versions of static web assets to determine
354+
what targets to invoke, what properties to set, and what properties to remove when doing so, for retrieving the referenced project static
355+
web assets. For earlier versions of static web assets we will collect the assets and "upgrade" them newer versions by providing default
356+
values for the additional metadata.
357+
-->
358+
<Target Name="GetStaticWebAssetsProjectConfiguration" Returns="@(_StaticWebAssetThisProjectConfiguration)">
359+
<ItemGroup>
360+
<_StaticWebAssetThisProjectConfiguration Include="$(MSBuildProjectFullPath)">
361+
<Version>1</Version>
362+
<Source>$(PackageId)</Source>
363+
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
364+
<GetBuildAssetsTargets>GetCurrentProjectStaticWebAssetsV2</GetBuildAssetsTargets>
365+
<AdditionalBuildProperties>$(StaticWebAssetsAdditionalBuildProperties)</AdditionalBuildProperties>
366+
<AdditionalBuildPropertiesToRemove>$(StaticWebAssetsAdditionalBuildPropertiesToRemove)</AdditionalBuildPropertiesToRemove>
367+
<GetPublishAssetsTargets></GetPublishAssetsTargets>
368+
</_StaticWebAssetThisProjectConfiguration>
369+
</ItemGroup>
370+
</Target>
371+
372+
<PropertyGroup>
373+
<GetCurrentProjectStaticWebAssetsV2DependsOn>GetCurrentProjectStaticWebAssets;$(GetCurrentProjectStaticWebAssetsV2DependsOn);</GetCurrentProjectStaticWebAssetsV2DependsOn>
374+
</PropertyGroup>
375+
376+
<Target Name="GetCurrentProjectStaticWebAssetsV2" DependsOnTargets="$(GetCurrentProjectStaticWebAssetsV2DependsOn)" Returns="@(_ThisProjectStaticWebAssetItems)">
377+
<ItemGroup>
378+
<_StaticWebAssetUpgradeMetadataToKeep Include="SourceType" />
379+
<_StaticWebAssetUpgradeMetadataToKeep Include="SourceId" />
380+
<_StaticWebAssetUpgradeMetadataToKeep Include="BasePath" />
381+
<_StaticWebAssetUpgradeMetadataToKeep Include="RelativePath" />
382+
<_StaticWebAssetUpgradeMetadataToKeep Include="ContentRoot" />
383+
<_StaticWebAssetUpgradeMetadataToKeep Include="AssetKind" />
384+
<_StaticWebAssetUpgradeMetadataToKeep Include="AssetMode" />
385+
<_StaticWebAssetUpgradeMetadataToKeep Include="AssetRole" />
386+
<_StaticWebAssetUpgradeMetadataToKeep Include="RelatedAsset" />
387+
<_StaticWebAssetUpgradeMetadataToKeep Include="AssetTraitName" />
388+
<_StaticWebAssetUpgradeMetadataToKeep Include="AssetTraitValue" />
389+
<_StaticWebAssetUpgradeMetadataToKeep Include="CopyToOutputDirectory" />
390+
<_StaticWebAssetUpgradeMetadataToKeep Include="CopyToPublishDirectory" />
391+
<_StaticWebAssetUpgradeMetadataToKeep Include="OriginalItemSpec" />
392+
393+
<_ThisProjectStaticWebAssetItems KeepMetadata="@(_StaticWebAssetUpgradeMetadataToKeep)" Include="@(_ThisProjectStaticWebAssets->'%(FullPath)')">
394+
<ResultType>StaticWebAsset</ResultType>
395+
<SourceType>Project</SourceType>
396+
<AssetKind Condition="'%(_ThisProjectStaticWebAssets.AssetKind)' == ''">All</AssetKind>
397+
<AssetMode Condition="'%(_ThisProjectStaticWebAssets.AssetMode)' == ''">All</AssetMode>
398+
<AssetRole Condition="'%(_ThisProjectStaticWebAssets.AssetRole)' == ''">Primary</AssetRole>
399+
<RelatedAsset Condition="'%(_ThisProjectStaticWebAssets.RelatedAsset)' == ''"></RelatedAsset>
400+
<AssetTraitName Condition="'%(_ThisProjectStaticWebAssets.AssetTraitName)' == ''"></AssetTraitName>
401+
<AssetTraitValue Condition="'%(_ThisProjectStaticWebAssets.AssetTraitValue)' == ''"></AssetTraitValue>
402+
<CopyToOutputDirectory Condition="'%(_ThisProjectStaticWebAssets.CopyToOutputDirectory)' == ''">Never</CopyToOutputDirectory>
403+
<CopyToPublishDirectory Condition="'%(_ThisProjectStaticWebAssets.CopyToPublishDirectory)' == ''">PreserveNewest</CopyToPublishDirectory>
404+
<OriginalItemSpec Condition="'%(_ThisProjectStaticWebAssets.OriginalItemSpec)' == ''">%(_ThisProjectStaticWebAssets.Identity)</OriginalItemSpec>
405+
</_ThisProjectStaticWebAssetItems>
406+
<_ThisProjectStaticWebAssetItems Include="$(PackageId)\wwwroot" Condition="Exists('$(MSBuildProjectDirectory)\wwwroot')">
407+
<ResultType>StaticWebAssetDiscoveryPattern</ResultType>
408+
<ContentRoot>$(MSBuildProjectDirectory)\wwwroot\</ContentRoot>
409+
<BasePath>$(StaticWebAssetBasePath)</BasePath>
410+
<Source>$(PackageId)</Source>
411+
<Pattern>**</Pattern>
412+
</_ThisProjectStaticWebAssetItems>
413+
</ItemGroup>
414+
</Target>
415+
352416
<!--
353417
============================================================
354418
Static web assets packing related targets

0 commit comments

Comments
 (0)