Skip to content

Commit fa5f52d

Browse files
committed
Try generating static assets in package targets
1 parent 6a93240 commit fa5f52d

File tree

3 files changed

+64
-172
lines changed

3 files changed

+64
-172
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web" DefaultTargets="Pack">
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
@@ -14,22 +14,8 @@
1414

1515
<!-- The package doesn't produce any lib or ref assemblies -->
1616
<NoWarn>$(NoWarn);NU5128</NoWarn>
17-
18-
<StaticWebAssetBasePath>_framework</StaticWebAssetBasePath>
19-
<DisableStaticWebAssetsBuildPropsFileGeneration>true</DisableStaticWebAssetsBuildPropsFileGeneration>
20-
<DisableStaticWebAssetEndpointsBuildPropsFileGeneration>true</DisableStaticWebAssetEndpointsBuildPropsFileGeneration>
21-
<StaticWebAssetsDisableProjectBuildPropsFileGeneration>true</StaticWebAssetsDisableProjectBuildPropsFileGeneration>
22-
<StaticWebAssetsDisableProjectBuildMultiTargetingPropsFileGeneration>true</StaticWebAssetsDisableProjectBuildMultiTargetingPropsFileGeneration>
23-
<StaticWebAssetsDisableProjectBuildTransitivePropsFileGeneration>true</StaticWebAssetsDisableProjectBuildTransitivePropsFileGeneration>
24-
<StaticWebAssetsGetBuildAssetsTargets>_GetFrameworkBuildAssets</StaticWebAssetsGetBuildAssetsTargets>
2517
</PropertyGroup>
2618

27-
<ItemGroup>
28-
<None Include="build\*" Pack="true" PackagePath="%(Identity)" />
29-
<None Include="buildMultiTargeting\*" Pack="true" PackagePath="%(Identity)" />
30-
<None Include="buildTransitive\*" Pack="true" PackagePath="%(Identity)" />
31-
</ItemGroup>
32-
3319
<PropertyGroup>
3420
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Debug'">$(RepoRoot)src\Components\Web.JS\dist\Debug</_BlazorJSContentRoot>
3521
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</_BlazorJSContentRoot>
@@ -44,8 +30,15 @@
4430
<_BlazorJSMapFile Include="@(_BlazorJSFilename->'$(_BlazorJSContentRoot)\%(Identity).map')" />
4531
</ItemGroup>
4632

47-
<Target Name="_CheckBlazorJSPath" AfterTargets="ResolveProjectReferences">
33+
<ItemGroup>
34+
<None Include="build\*" Pack="true" PackagePath="%(Identity)" />
35+
<None Include="buildMultiTargeting\*" Pack="true" PackagePath="%(Identity)" />
36+
<None Include="buildTransitive\*" Pack="true" PackagePath="%(Identity)" />
37+
<None Include="@(_BlazorJSFile)" Pack="true" PackagePath="_framework\%(FileName)%(Extension)" />
38+
<None Include="@(_BlazorJSMapFile)" Pack="true" PackagePath="_framework\debug\%(FileName)%(Extension)" />
39+
</ItemGroup>
4840

41+
<Target Name="_CheckBlazorJSPath" AfterTargets="ResolveProjectReferences">
4942
<ItemGroup>
5043
<_MissingBlazorJSFile Include="@(_BlazorJSFile)" Condition="!EXISTS('%(_BlazorJSFile.FullPath)')" />
5144
<_MissingBlazorJSFile Include="@(_BlazorJSMapFile)" Condition="!EXISTS('%(_BlazorJSMapFile.FullPath)')" />
@@ -54,149 +47,6 @@
5447
<Error
5548
Condition="'@(_MissingBlazorJSFile)' != ''"
5649
Text="'%(_MissingBlazorJSFile.Identity)' does not exist. Run 'npm run build' in the repo root to generate the file." />
57-
58-
</Target>
59-
60-
<Target Name="_GetFrameworkBuildAssets" Returns="@(ReferenceAsset)">
61-
62-
<ItemGroup>
63-
<_ReferenceAssetCandidates Include="@(_BlazorJSFile)" />
64-
<_ReferenceAssetCandidates Include="@(_BlazorJSMapFile)" />
65-
<_ReferenceAssetCandidates>
66-
<RelativePath>$(StaticWebAssetBasePath)\%(FileName)%(Extension)</RelativePath>
67-
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
68-
</_ReferenceAssetCandidates>
69-
</ItemGroup>
70-
71-
<DefineStaticWebAssets
72-
Condition="'@(_ReferenceAssetCandidates->Count())' != '0'"
73-
CandidateAssets="@(_ReferenceAssetCandidates)"
74-
SourceId="$(PackageId)"
75-
SourceType="Discovered"
76-
AssetKind="All"
77-
FingerprintCandidates="true"
78-
BasePath="$(StaticWebAssetBasePath)"
79-
>
80-
<Output TaskParameter="Assets" ItemName="ReferenceAsset" />
81-
</DefineStaticWebAssets>
82-
83-
<ItemGroup>
84-
<ReferenceAsset>
85-
<ResultType>StaticWebAsset</ResultType>
86-
</ReferenceAsset>
87-
</ItemGroup>
88-
89-
</Target>
90-
91-
<Target Name="_GenerateFrameworkPackItems" BeforeTargets="GenerateStaticWebAssetsPackFiles">
92-
<ItemGroup>
93-
<_AssetCandidates Include="@(_BlazorJSFile)" />
94-
<_AssetCandidates>
95-
<RelativePath>%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
96-
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
97-
</_AssetCandidates>
98-
99-
<_DebugAssetCandidates Include="@(_BlazorJSMapFile)" />
100-
<_DebugAssetCandidates>
101-
<RelativePath>%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
102-
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
103-
</_DebugAssetCandidates>
104-
</ItemGroup>
105-
106-
<DefineStaticWebAssets
107-
Condition="'@(_AssetCandidates->Count())' != '0'"
108-
CandidateAssets="@(_AssetCandidates)"
109-
AssetKind="All"
110-
SourceId="$(PackageId)"
111-
SourceType="Discovered"
112-
FingerprintCandidates="true"
113-
BasePath="$(StaticWebAssetBasePath)"
114-
>
115-
<Output TaskParameter="Assets" ItemName="_FrameworkAssets" />
116-
</DefineStaticWebAssets>
117-
118-
<DefineStaticWebAssets
119-
Condition="'@(_DebugAssetCandidates->Count())' != '0'"
120-
CandidateAssets="@(_DebugAssetCandidates)"
121-
AssetKind="All"
122-
SourceId="$(PackageId)"
123-
SourceType="Discovered"
124-
FingerprintCandidates="true"
125-
BasePath="$(StaticWebAssetBasePath)"
126-
>
127-
<Output TaskParameter="Assets" ItemName="_DebugFrameworkAssets" />
128-
</DefineStaticWebAssets>
129-
130-
<DefineStaticWebAssetEndpoints
131-
Condition="'@(_FrameworkAssets)' != ''"
132-
CandidateAssets="@(_FrameworkAssets)"
133-
ExistingEndpoints="@()"
134-
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
135-
<Output TaskParameter="Endpoints" ItemName="_FrameworkAssetEndpoints" />
136-
</DefineStaticWebAssetEndpoints>
137-
138-
<DefineStaticWebAssetEndpoints
139-
Condition="'@(_DebugFrameworkAssets)' != ''"
140-
CandidateAssets="@(_DebugFrameworkAssets)"
141-
ExistingEndpoints="@()"
142-
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
143-
<Output TaskParameter="Endpoints" ItemName="_DebugFrameworkAssetEndpoints" />
144-
</DefineStaticWebAssetEndpoints>
145-
146-
<ComputeEndpointsForReferenceStaticWebAssets
147-
Assets="@(_FrameworkAssets)"
148-
CandidateEndpoints="@(_FrameworkAssetEndpoints)">
149-
<Output TaskParameter="Endpoints" ItemName="_PackFrameworkAssetEndpoints" />
150-
</ComputeEndpointsForReferenceStaticWebAssets>
151-
152-
<ComputeEndpointsForReferenceStaticWebAssets
153-
Assets="@(_DebugFrameworkAssets)"
154-
CandidateEndpoints="@(_DebugFrameworkAssetEndpoints)">
155-
<Output TaskParameter="Endpoints" ItemName="_PackDebugFrameworkAssetEndpoints" />
156-
</ComputeEndpointsForReferenceStaticWebAssets>
157-
158-
<GenerateStaticWebAssetsPropsFile
159-
StaticWebAssets="@(_FrameworkAssets)"
160-
PackagePathPrefix="staticwebassets"
161-
TargetPropsFilePath="$(IntermediateOutputPath)Assets.Pack.targets" />
162-
163-
<GenerateStaticWebAssetsPropsFile
164-
StaticWebAssets="@(_DebugFrameworkAssets)"
165-
PackagePathPrefix="staticwebassets"
166-
TargetPropsFilePath="$(IntermediateOutputPath)Assets.Pack.debug.targets" />
167-
168-
<GenerateStaticWebAssetEndpointsPropsFile
169-
StaticWebAssets="@(_FrameworkAssets)"
170-
StaticWebAssetEndpoints="@(_PackFrameworkAssetEndpoints)"
171-
TargetPropsFilePath="$(IntermediateOutputPath)Assets.Pack.endpoints.targets" />
172-
173-
<GenerateStaticWebAssetEndpointsPropsFile
174-
StaticWebAssets="@(_DebugFrameworkAssets)"
175-
StaticWebAssetEndpoints="@(_PackDebugFrameworkAssetEndpoints)"
176-
TargetPropsFilePath="$(IntermediateOutputPath)Assets.Pack.debug.endpoints.targets" />
177-
178-
<ComputeStaticWebAssetsTargetPaths Assets="@(_FrameworkAssets)" PathPrefix="staticwebassets" AdjustPathsForPack="true">
179-
<Output TaskParameter="AssetsWithTargetPath" ItemName="_PackStaticWebAssetWithTargetPath" />
180-
</ComputeStaticWebAssetsTargetPaths>
181-
<ComputeStaticWebAssetsTargetPaths Assets="@(_DebugFrameworkAssets)" PathPrefix="staticwebassets" AdjustPathsForPack="true">
182-
<Output TaskParameter="AssetsWithTargetPath" ItemName="_PackStaticWebAssetWithTargetPath" />
183-
</ComputeStaticWebAssetsTargetPaths>
184-
185-
<ItemGroup>
186-
<StaticWebAssetPackageFile Include="$(IntermediateOutputPath)Assets.Pack.targets">
187-
<PackagePath>build\Microsoft.AspNetCore.StaticWebAssets.targets</PackagePath>
188-
</StaticWebAssetPackageFile>
189-
<StaticWebAssetPackageFile Include="$(IntermediateOutputPath)Assets.Pack.endpoints.targets">
190-
<PackagePath>build\Microsoft.AspNetCore.StaticWebAssets.endpoints.targets</PackagePath>
191-
</StaticWebAssetPackageFile>
192-
<StaticWebAssetPackageFile Include="$(IntermediateOutputPath)Assets.Pack.debug.targets">
193-
<PackagePath>build\Microsoft.AspNetCore.StaticWebAssets.debug.targets</PackagePath>
194-
</StaticWebAssetPackageFile>
195-
<StaticWebAssetPackageFile Include="$(IntermediateOutputPath)Assets.Pack.debug.endpoints.targets">
196-
<PackagePath>build\Microsoft.AspNetCore.StaticWebAssets.debug.endpoints.targets</PackagePath>
197-
</StaticWebAssetPackageFile>
198-
</ItemGroup>
199-
20050
</Target>
20151

20252
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
<Project>
2-
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.StaticWebAssets.targets" />
3-
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.StaticWebAssets.endpoints.targets" />
2+
<PropertyGroup>
3+
<ResolveStaticWebAssetsInputsDependsOn>
4+
$(ResolveStaticWebAssetsInputsDependsOn);
5+
_AddBlazorFrameworkStaticWebAssets;
6+
</ResolveStaticWebAssetsInputsDependsOn>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<BlazorFrameworkStaticWebAssetRoot Condition="'$(BlazorFrameworkStaticWebAssetRoot)' == ''">$(MSBuildThisFileDirectory)..\_framework</BlazorFrameworkStaticWebAssetRoot>
11+
<BlazorFrameworkStaticWebAssetDebugRoot Condition="'$(BlazorFrameworkStaticWebAssetDebugRoot)' == ''">$(MSBuildThisFileDirectory)..\_framework\debug</BlazorFrameworkStaticWebAssetDebugRoot>
12+
</PropertyGroup>
13+
14+
<Target Name="_AddBlazorFrameworkStaticWebAssets" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' AND '$(OutputType)' == 'Exe'">
15+
<ItemGroup>
16+
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\*" />
17+
<_FrameworkStaticWebAssetCandidate
18+
Condition="'$(UseDebugBlazorAssets)' == 'true'"
19+
Include="$(BlazorFrameworkStaticWebAssetDebugRoot)\*" />
20+
<_FrameworkStaticWebAssetCandidate>
21+
<RelativePath>_framework\%(FileName)%(Extension)</RelativePath>
22+
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
23+
</_FrameworkStaticWebAssetCandidate>
24+
</ItemGroup>
25+
26+
<DefineStaticWebAssets
27+
Condition="'@(_FrameworkStaticWebAssetCandidate->Count())' != '0'"
28+
CandidateAssets="@(_FrameworkStaticWebAssetCandidate)"
29+
SourceId="$(PackageId)"
30+
SourceType="Discovered"
31+
AssetKind="All"
32+
FingerprintCandidates="true"
33+
BasePath="$(StaticWebAssetBasePath)">
34+
<Output TaskParameter="Assets" ItemName="_FrameworkStaticWebAsset" />
35+
</DefineStaticWebAssets>
36+
37+
<DefineStaticWebAssetEndpoints
38+
Condition="'@(_FrameworkStaticWebAsset)' != ''"
39+
CandidateAssets="@(_FrameworkStaticWebAsset)"
40+
ExistingEndpoints="@()"
41+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
42+
<Output TaskParameter="Endpoints" ItemName="_FrameworkStaticAssetEndpoint" />
43+
</DefineStaticWebAssetEndpoints>
44+
45+
<ItemGroup>
46+
<StaticWebAsset Include="@(_FrameworkStaticWebAsset)" />
47+
<StaticWebAssetEndpoint Include="@(_FrameworkStaticAssetEndpoint)" />
48+
</ItemGroup>
49+
</Target>
450

5-
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.StaticWebAssets.debug.targets"
6-
Condition="'$(UseDebugBlazorAssets)' == 'true'" />
7-
<Import Project="$(MSBuildThisFileDirectory)Microsoft.AspNetCore.StaticWebAssets.debug.endpoints.targets"
8-
Condition="'$(UseDebugBlazorAssets)' == 'true'"/>
951
</Project>

src/Components/Directory.Build.props

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
1919
</PropertyGroup>
2020

21-
<ItemGroup>
22-
<!-- Temporary: Remove after package is provided by the SDK -->
23-
<Reference
24-
Condition="'$(UsingMicrosoftNETSdkRazor)' == 'true' AND '$(OutputType)' == 'Exe'"
25-
Include="Microsoft.AspNetCore.App.Internal.Assets"
26-
ReferenceOutputAssembly="false" />
27-
</ItemGroup>
21+
<!-- Workaround to add Blazor framework static assets without requiring a package reference -->
22+
<PropertyGroup>
23+
<BlazorFrameworkStaticWebAssetRoot Condition="'$(Configuration)' == 'Debug'">$(RepoRoot)src\Components\Web.JS\dist\Debug</BlazorFrameworkStaticWebAssetRoot>
24+
<BlazorFrameworkStaticWebAssetRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</BlazorFrameworkStaticWebAssetRoot>
25+
</PropertyGroup>
26+
27+
<Import Project="$(RepoRoot)\src\Assets\build\Microsoft.AspNetCore.App.Internal.Assets.targets" />
2828

2929
</Project>

0 commit comments

Comments
 (0)