Skip to content

Follow-up to #31559 #32047

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

Merged
merged 3 commits into from
May 8, 2023
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
25 changes: 25 additions & 0 deletions src/RazorSdk/Targets/Sdk.Razor.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ Copyright (c) .NET Foundation. All rights reserved.
ResolveRazorEmbeddedResources;
</ResolveRazorCompileInputsDependsOn>

<ResolveScopedCssOutputsDependsOn>
$(ResolveScopedCssOutputsDependsOn);
ResolveCssScopes;
</ResolveScopedCssOutputsDependsOn>

<DebugSymbolsProjectOutputGroupDependsOn>
$(DebugSymbolsProjectOutputGroupDependsOn);
_RazorAddDebugSymbolsProjectOutputGroupOutput
Expand Down Expand Up @@ -544,6 +549,26 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>
</Target>

<!-- This target validates that there is at most one scoped css file per component, that there are no scoped css files without a
matching component, and then adds the associated scope to the razor components that have a matching scoped css file.
-->
<Target
Name="ResolveCssScopes"
Condition="'$(ScopedCssEnabled)' == 'true'"
BeforeTargets="AssignRazorComponentTargetPaths;AssignRazorGenerateTargetPaths"
DependsOnTargets="ComputeCssScope;ResolveRazorComponentInputs;ResolveRazorGenerateInputs">
<ApplyCssScopes RazorComponents="@(RazorComponent)" RazorGenerate="@(RazorGenerate)" ScopedCss="@(_ScopedCss)">
<Output TaskParameter="RazorComponentsWithScopes" ItemName="_RazorComponentsWithScopes" />
<Output TaskParameter="RazorGenerateWithScopes" ItemName="_RazorGenerateWithScopes" />
</ApplyCssScopes>
<ItemGroup>
<RazorComponent Remove="@(_RazorComponentsWithScopes)" />
<RazorComponent Include="@(_RazorComponentsWithScopes)" />
<RazorGenerate Remove="@(_RazorGenerateWithScopes)" />
<RazorGenerate Include="@(_RazorGenerateWithScopes)" />
</ItemGroup>
</Target>

<!--
Temporarary workaround for https://github.com/dotnet/aspnetcore/issues/6859. This can be removed after a VS insertion with a newer copy of the DesignTime targets.
-->
Expand Down
1 change: 0 additions & 1 deletion src/RazorSdk/Tool/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public Application(
Commands.Add(new ShutdownCommand(this));
Commands.Add(new DiscoverCommand(this));
Commands.Add(new GenerateCommand(this));
Commands.Add(new RewriteCssCommand(this));
}

public CancellationToken CancellationToken { get; }
Expand Down
432 changes: 0 additions & 432 deletions src/RazorSdk/Tool/RewriteCssCommand.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<GZipCompress Condition="'@(_GZipCompressedStaticWebAssets)' != ''"
FilesToCompress="@(_GZipCompressedStaticWebAssets)" />

<BrotliCompress
<BrotliCompress Condition="'@(_BrotliCompressedStaticWebAssets)' != ''"
FilesToCompress="@(_BrotliCompressedStaticWebAssets)"
CompressionLevel="$(_BlazorBrotliCompressionLevel)"
ToolAssembly="$(_StaticWebAssetsSdkToolAssembly)"
Expand All @@ -155,7 +155,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<GZipCompress Condition="'@(_GZipCompressedStaticWebAssetsForPublish)' != ''"
FilesToCompress="@(_GZipCompressedStaticWebAssetsForPublish)" />

<BrotliCompress
<BrotliCompress Condition="'@(_BrotliCompressedStaticWebAssetsForPublish)' != ''"
FilesToCompress="@(_BrotliCompressedStaticWebAssetsForPublish)"
CompressionLevel="$(_BlazorBrotliCompressionLevel)"
ToolAssembly="$(_StaticWebAssetsSdkToolAssembly)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Copyright (c) .NET Foundation. All rights reserved.

</PropertyGroup>

<Target Name="_ResolveJsModuleInputs" BeforeTargets="AssignRazorComponentTargetPaths;AssignRazorGenerateTargetPaths" DependsOnTargets="ResolveProjectStaticWebAssets">
<Target Name="_ResolveJsModuleInputs" DependsOnTargets="ResolveProjectStaticWebAssets">

<ItemGroup>
<_JSModuleCandidates Include="@(StaticWebAsset)" Condition="'%(SourceType)' == 'Discovered'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Integration with static web assets:
_AddScopedCssBundles;
</ResolveStaticWebAssetsInputsDependsOn>

<ResolveScopedCssOutputsDependsOn>
$(ResolveScopedCssOutputsDependsOn);
</ResolveScopedCssOutputsDependsOn>

<!-- When used as a reference, the app will have been built before and as a result the list of static web assets will include the bundle
instead of the individual files. We need to correct that in GetCopyToOuputDirectoryItems -->

Expand Down Expand Up @@ -135,31 +139,15 @@ Integration with static web assets:
</Target>

<!-- This target just generates a Scope identifier for the items that we deemed were scoped css files -->
<Target Name="_ComputeCssScope" DependsOnTargets="ResolveScopedCssInputs">
<Target Name="ComputeCssScope" DependsOnTargets="ResolveScopedCssInputs">
<ComputeCssScope ScopedCssInput="@(ScopedCssInput)" Targetname="$(TargetName)">
<Output TaskParameter="ScopedCss" ItemName="_ScopedCss" />
</ComputeCssScope>
</Target>

<!-- This target validates that there is at most one scoped css file per component, that there are no scoped css files without a
matching component, and then adds the associated scope to the razor components that have a matching scoped css file.
-->
<Target Name="_ResolveCssScopes" BeforeTargets="AssignRazorComponentTargetPaths;AssignRazorGenerateTargetPaths" DependsOnTargets="_ComputeCssScope;ResolveRazorComponentInputs;ResolveRazorGenerateInputs">
<ApplyCssScopes RazorComponents="@(RazorComponent)" RazorGenerate="@(RazorGenerate)" ScopedCss="@(_ScopedCss)">
<Output TaskParameter="RazorComponentsWithScopes" ItemName="_RazorComponentsWithScopes" />
<Output TaskParameter="RazorGenerateWithScopes" ItemName="_RazorGenerateWithScopes" />
</ApplyCssScopes>
<ItemGroup>
<RazorComponent Remove="@(_RazorComponentsWithScopes)" />
<RazorComponent Include="@(_RazorComponentsWithScopes)" />
<RazorGenerate Remove="@(_RazorGenerateWithScopes)" />
<RazorGenerate Include="@(_RazorGenerateWithScopes)" />
</ItemGroup>
</Target>

<!-- Sets the output path for the processed scoped css files. They will all have a '.rz.scp.css' extension to flag them as processed
scoped css files. -->
<Target Name="_ResolveScopedCssOutputs" DependsOnTargets="_ResolveCssScopes">
<Target Name="ResolveScopedCssOutputs" DependsOnTargets="$(ResolveScopedCssOutputsDependsOn)">
<PropertyGroup>
<_ScopedCssIntermediatePath>$([System.IO.Path]::GetFullPath($(IntermediateOutputPath)scopedcss\))</_ScopedCssIntermediatePath>
</PropertyGroup>
Expand All @@ -181,19 +169,14 @@ Integration with static web assets:

<Target
Name="_ResolveScopedCssOutputsDesignTime"
DependsOnTargets="_ResolveScopedCssOutputs"
DependsOnTargets="ResolveScopedCssOutputs"
BeforeTargets="CollectUpToDateCheckInputDesignTime;CollectUpToDateCheckBuiltDesignTime" />

<!-- Transforms the original scoped CSS files into their scoped versions on their designated output paths -->
<Target Name="_GenerateScopedCssFiles" Inputs="@(_ScopedCss)" Outputs="@(_ScopedCssOutputs)" DependsOnTargets="_ResolveScopedCssOutputs">
<Target Name="_GenerateScopedCssFiles" Inputs="@(_ScopedCss)" Outputs="@(_ScopedCssOutputs)" DependsOnTargets="ResolveScopedCssOutputs">

<MakeDir Directories="$(_ScopedCssIntermediatePath)" />
<RewriteCss
FilesToTransform="@(_ScopedCss)"
ToolAssembly="$(_StaticWebAssetsSdkRazorToolAssembly)"
ToolExe="$(_StaticWebAssetsSdkDotNetHostFileName)"
ToolPath="$(_StaticWebAssetsSdkDotNetHostDirectory)">
</RewriteCss>
<RewriteCss FilesToTransform="@(_ScopedCss)" />

<ItemGroup>
<FileWrites Include="%(_ScopedCss.OutputFile)" />
Expand Down Expand Up @@ -324,7 +307,7 @@ Integration with static web assets:
<!-- This target is only called as part of GetCurrentProjectStaticWebAssets which is only invoked on referenced projects to get the list
of their assets. We return the list of css outputs we will produce and let the main app do the final bundling. -->

<Target Name="_AddGeneratedScopedCssFiles" DependsOnTargets="_ResolveScopedCssOutputs;ResolveStaticWebAssetsConfiguration">
<Target Name="_AddGeneratedScopedCssFiles" DependsOnTargets="ResolveScopedCssOutputs;ResolveStaticWebAssetsConfiguration">
<!-- We do this in two steps because we will be modifying the list of static web assets if we bundle the files and these assets need to be
available when called from GetCurrentProjectStaticWebAssets -->
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Integration with static web assets:
BundleScopedCssFiles;
</GenerateComputedBuildStaticWebAssetsDependsOn>

<ResolveScopedCssOutputsDependsOn>
$(ResolveScopedCssOutputsDependsOn);
</ResolveScopedCssOutputsDependsOn>

</PropertyGroup>

<PropertyGroup Condition="'$(DisableScopedCssBundling)' == 'true'">
Expand All @@ -80,6 +84,10 @@ Integration with static web assets:
$(GenerateComputedBuildStaticWebAssetsDependsOn);
</GenerateComputedBuildStaticWebAssetsDependsOn>

<ResolveScopedCssOutputsDependsOn>
$(ResolveScopedCssOutputsDependsOn);
</ResolveScopedCssOutputsDependsOn>

</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -113,31 +121,15 @@ Integration with static web assets:
</Target>

<!-- This target just generates a Scope identifier for the items that we deemed were scoped css files -->
<Target Name="_ComputeCssScope" DependsOnTargets="ResolveScopedCssInputs">
<Target Name="ComputeCssScope" DependsOnTargets="ResolveScopedCssInputs">
<ComputeCssScope ScopedCssInput="@(ScopedCssInput)" Targetname="$(TargetName)">
<Output TaskParameter="ScopedCss" ItemName="_ScopedCss" />
</ComputeCssScope>
</Target>

<!-- This target validates that there is at most one scoped css file per component, that there are no scoped css files without a
matching component, and then adds the associated scope to the razor components that have a matching scoped css file.
-->
<Target Name="_ResolveCssScopes" BeforeTargets="AssignRazorComponentTargetPaths;AssignRazorGenerateTargetPaths" DependsOnTargets="_ComputeCssScope;ResolveRazorComponentInputs;ResolveRazorGenerateInputs">
<ApplyCssScopes RazorComponents="@(RazorComponent)" RazorGenerate="@(RazorGenerate)" ScopedCss="@(_ScopedCss)">
<Output TaskParameter="RazorComponentsWithScopes" ItemName="_RazorComponentsWithScopes" />
<Output TaskParameter="RazorGenerateWithScopes" ItemName="_RazorGenerateWithScopes" />
</ApplyCssScopes>
<ItemGroup>
<RazorComponent Remove="@(_RazorComponentsWithScopes)" />
<RazorComponent Include="@(_RazorComponentsWithScopes)" />
<RazorGenerate Remove="@(_RazorGenerateWithScopes)" />
<RazorGenerate Include="@(_RazorGenerateWithScopes)" />
</ItemGroup>
</Target>

<!-- Sets the output path for the processed scoped css files. They will all have a '.rz.scp.css' extension to flag them as processed
scoped css files. -->
<Target Name="_ResolveScopedCssOutputs" DependsOnTargets="_ResolveCssScopes">
<Target Name="ResolveScopedCssOutputs" DependsOnTargets="$(ResolveScopedCssOutputsDependsOn)">
<PropertyGroup>
<_ScopedCssIntermediatePath>$([System.IO.Path]::GetFullPath($(IntermediateOutputPath)scopedcss\))</_ScopedCssIntermediatePath>
</PropertyGroup>
Expand All @@ -160,19 +152,14 @@ Integration with static web assets:

<Target
Name="_ResolveScopedCssOutputsDesignTime"
DependsOnTargets="_ResolveScopedCssOutputs"
DependsOnTargets="ResolveScopedCssOutputs"
BeforeTargets="CollectUpToDateCheckInputDesignTime;CollectUpToDateCheckBuiltDesignTime" />

<!-- Transforms the original scoped CSS files into their scoped versions on their designated output paths -->
<Target Name="_GenerateScopedCssFiles" Inputs="@(_ScopedCss)" Outputs="@(_ScopedCssOutputs)" DependsOnTargets="_ResolveScopedCssOutputs">
<Target Name="_GenerateScopedCssFiles" Inputs="@(_ScopedCss)" Outputs="@(_ScopedCssOutputs)" DependsOnTargets="ResolveScopedCssOutputs">

<MakeDir Directories="$(_ScopedCssIntermediatePath)" />
<RewriteCss
FilesToTransform="@(_ScopedCss)"
ToolAssembly="$(_StaticWebAssetsSdkRazorToolAssembly)"
ToolExe="$(_StaticWebAssetsSdkDotNetHostFileName)"
ToolPath="$(_StaticWebAssetsSdkDotNetHostDirectory)">
</RewriteCss>
<RewriteCss FilesToTransform="@(_ScopedCss)" />

<ItemGroup>
<FileWrites Include="%(_ScopedCss.OutputFile)" />
Expand Down Expand Up @@ -298,7 +285,7 @@ Integration with static web assets:

</Target>

<Target Name="_ComputeScopedCssStaticWebAssets" DependsOnTargets="_ResolveScopedCssOutputs;ResolveStaticWebAssetsConfiguration">
<Target Name="_ComputeScopedCssStaticWebAssets" DependsOnTargets="ResolveScopedCssOutputs;ResolveStaticWebAssetsConfiguration">
<ItemGroup>
<_ScopedCssCandidateFile Include="%(_ScopedCss.OutputFile)" Condition="@(_ScopedCss) != ''">
<RelativePath>%(_ScopedCss.RelativePath)</RelativePath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<_StaticWebAssetsSdkTasksTFM Condition=" '$(_StaticWebAssetsSdkTasksTFM)' == ''">net472</_StaticWebAssetsSdkTasksTFM>
<StaticWebAssetsSdkBuildTasksAssembly>$(StaticWebAssetsSdkBuildTasksDirectoryRoot)$(_StaticWebAssetsSdkTasksTFM)\Microsoft.NET.Sdk.StaticWebAssets.Tasks.dll</StaticWebAssetsSdkBuildTasksAssembly>
<_StaticWebAssetsSdkToolAssembly>$(StaticWebAssetsSdkDirectoryRoot)tools\net8.0\Microsoft.NET.Sdk.StaticWebAssets.Tool.dll</_StaticWebAssetsSdkToolAssembly>
<_StaticWebAssetsSdkRazorToolAssembly>$(StaticWebAssetsSdkDirectoryRoot)..\Microsoft.NET.Sdk.Razor\tools\rzc.dll</_StaticWebAssetsSdkRazorToolAssembly>
</PropertyGroup>

<PropertyGroup Condition="'$(DOTNET_HOST_PATH)' == ''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,11 @@
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" Condition="'$(TargetFramework)'=='net472'" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" Condition="'$(TargetFramework)'=='net472'" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(MicrosoftExtensionsFileSystemGlobbingPackageVersion)" />
<PackageReference Include="Microsoft.Css.Parser" Version="$(MicrosoftCssParserVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
<Compile Include="..\..\RazorSdk\Tool\CommandLine\ArgumentEscaper.cs">
<Link>Shared\CommandLine\%(FileName)</Link>
</Compile>
<Compile Include="..\..\RazorSdk\Tool\ServerProtocol\*.cs">
<Link>Shared\ServerProtocol\%(FileName)</Link>
</Compile>
<Compile Include="..\..\RazorSdk\Tool\PipeName.cs">
<Link>Shared\PipeName.cs</Link>
</Compile>
<Compile Include="..\..\RazorSdk\Tool\MutexName.cs">
<Link>Shared\MutexName.cs</Link>
</Compile>
<Compile Include="..\..\RazorSdk\Tool\Client.cs">
<Link>Shared\Client.cs</Link>
</Compile>
<Compile Include="..\..\RazorSdk\Tasks\DotnetToolTask.cs">
<Link>Shared\DotnetToolTask.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -95,6 +78,18 @@
</Copy>
</Target>

<Target Name="CopyCssParser" BeforeTargets="PrepareAdditionalFilesToLayout" AfterTargets="ResolveReferences" Condition="'$(TargetFramework)' == '$(SdkTargetFramework)'">
<ItemGroup>
<_CssParser Include="@(ReferencePath)" Condition="'%(ReferencePath.NuGetPackageId)' == 'Microsoft.Css.Parser'" />
<_CssParserContent Include ="@(_CssParser)" TargetPath="tasks\$(SdkTargetFramework)\%(_CssParser.Filename)%(_CssParser.Extension)" />
<AdditionalContent Include="@(_CssParser)" PackagePath="tasks\$(SdkTargetFramework)" />
</ItemGroup>

<Copy SourceFiles="@(_CssParserContent)" DestinationFiles="@(_CssParserContent->'$(PackageLayoutOutputPath)%(TargetPath)')">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>
</Target>

<Target Name="PrepareAdditionalFilesToLayout" BeforeTargets="AssignTargetPaths">
<ItemGroup>
<LayoutFile Include="@(AdditionalContent)" Condition="'%(AdditionalContent.PackagePath)' != '' and '%(AdditionalContent.PackagePath)' != 'Icon.png'">
Expand Down
Loading