Skip to content

Commit 72862c3

Browse files
committed
More code
1 parent 58d5642 commit 72862c3

17 files changed

+819
-59
lines changed

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.Compression.targets

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,18 @@ Copyright (c) .NET Foundation. All rights reserved.
235235
<ItemGroup>
236236
<StaticWebAsset Include="@(_CompressionBuildStaticWebAsset)" />
237237
<StaticWebAssetEndpoint Include="@(_CompressionBuildStaticWebAssetEndpoint)" />
238+
<_CompressionCurrentProjectBuildAssets Include="@(StaticWebAsset)" />
238239
</ItemGroup>
239240

240-
<ComputeStaticWebAssetsForCurrentProject
241+
<!-- <ComputeStaticWebAssetsForCurrentProject
241242
Assets="@(StaticWebAsset)"
242243
ProjectMode="$(StaticWebAssetProjectMode)"
243244
AssetKind="Build"
245+
IncludeReferenceAssets="true"
244246
Source="$(PackageId)"
245247
>
246248
<Output TaskParameter="StaticWebAssets" ItemName="_CompressionCurrentProjectBuildAssets" />
247-
</ComputeStaticWebAssetsForCurrentProject>
249+
</ComputeStaticWebAssetsForCurrentProject> -->
248250

249251
<ApplyCompressionNegotiation
250252
CandidateEndpoints="@(StaticWebAssetEndpoint)"
@@ -325,16 +327,18 @@ Copyright (c) .NET Foundation. All rights reserved.
325327
<ItemGroup>
326328
<StaticWebAsset Include="@(_CompressionPublishStaticWebAsset)" />
327329
<StaticWebAssetEndpoint Include="@(_CompressionPublishStaticWebAssetEndpoint)" />
330+
<_CompressionCurrentProjectPublishAssets Include="@(StaticWebAsset)" Condition="'%(AssetKind)' != 'Build'" />
328331
</ItemGroup>
329332

330-
<ComputeStaticWebAssetsForCurrentProject
333+
<!-- <ComputeStaticWebAssetsForCurrentProject
331334
Assets="@(StaticWebAsset)"
332335
ProjectMode="$(StaticWebAssetProjectMode)"
333336
AssetKind="Publish"
337+
IncludeReferenceAssets="true"
334338
Source="$(PackageId)"
335339
>
336340
<Output TaskParameter="StaticWebAssets" ItemName="_CompressionCurrentProjectPublishAssets" />
337-
</ComputeStaticWebAssetsForCurrentProject>
341+
</ComputeStaticWebAssetsForCurrentProject> -->
338342

339343
<ApplyCompressionNegotiation
340344
CandidateEndpoints="@(StaticWebAssetEndpoint)"

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.JSModules.targets

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,31 @@ Copyright (c) .NET Foundation. All rights reserved.
295295
<Output TaskParameter="Assets" ItemName="_MvcJSModule" />
296296
</DefineStaticWebAssets>
297297

298+
<DefineStaticWebAssetEndpoints
299+
CandidateAssets="@(_ComponentJSModule)"
300+
ExistingEndpoints="@(StaticWebAssetEndpoint)"
301+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
302+
<Output TaskParameter="Endpoints" ItemName="_ComponentJSModuleEndpoint" />
303+
</DefineStaticWebAssetEndpoints>
304+
305+
<DefineStaticWebAssetEndpoints
306+
CandidateAssets="@(_MvcJSModule)"
307+
ExistingEndpoints="@(StaticWebAssetEndpoint)"
308+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
309+
<Output TaskParameter="Endpoints" ItemName="_MvcJSModuleEndpoint" />
310+
</DefineStaticWebAssetEndpoints>
311+
298312
<ApplyJsModules RazorComponents="@(RazorComponent)" RazorGenerate="@(RazorGenerate)" JSFileModuleCandidates="@(_ComponentJSModule);@(_MvcJSModule)">
299313
<Output TaskParameter="JsFileModules" ItemName="_JsFileModuleStaticWebAsset" />
300314
</ApplyJsModules>
301315

302316
<ItemGroup>
303317
<StaticWebAsset Remove="@(_JsFileModuleStaticWebAsset)" />
304318
<StaticWebAsset Include="@(_JsFileModuleStaticWebAsset)" />
319+
320+
<StaticWebAssetEndpoint Include="@(_ComponentJSModuleEndpoint)" />
321+
<StaticWebAssetEndpoint Include="@(_MvcJSModuleEndpoint)" />
322+
305323
<!-- Remove the items from their original groups since they've now become a StaticWebAsset -->
306324
<Content Remove="@(_JsFileModuleStaticWebAsset->'%(OriginalItemSpec)')" />
307325
<None Remove="@(_JsFileModuleStaticWebAsset->'%(OriginalItemSpec)')" />

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.References.targets

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,37 @@ Copyright (c) .NET Foundation. All rights reserved.
105105
</MSBuild>
106106

107107
<ItemGroup>
108-
109-
<StaticWebAsset
108+
<_ResolvedReferencedProjectBuildStaticWebAssets
110109
Include="@(_ReferencedProjectBuildStaticWebAssetsItems)"
111110
Condition="'%(_ReferencedProjectBuildStaticWebAssetsItems.ResultType)' == 'StaticWebAsset'"
112111
KeepMetadata="@(_StaticWebAssetCanonicalMetadata)" />
113112

114-
<StaticWebAssetEndpoint
113+
<_ResolvedReferencedProjectBuildStaticWebAssetEndpoints
115114
Include="@(_ReferencedProjectBuildStaticWebAssetsItems)"
116115
Condition="'%(_ReferencedProjectBuildStaticWebAssetsItems.ResultType)' == 'StaticWebAssetEndpoint'"
117116
KeepMetadata="@(_StaticWebAssetEndpointCanonicalMetadata)" />
117+
</ItemGroup>
118+
119+
<DefineStaticWebAssetEndpoints
120+
CandidateAssets="@(_ResolvedReferencedProjectBuildStaticWebAssets)"
121+
ExistingEndpoints="@(_ResolvedReferencedProjectBuildStaticWebAssetEndpoints)"
122+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
123+
>
124+
<Output TaskParameter="Endpoints" ItemName="_MissingReferencedProjectBuildStaticWebAssetEndpoints" />
125+
</DefineStaticWebAssetEndpoints>
126+
127+
<ItemGroup>
128+
129+
<StaticWebAsset Include="@(_ResolvedReferencedProjectBuildStaticWebAssets)" />
130+
131+
<StaticWebAssetEndpoint Include="@(_ResolvedReferencedProjectBuildStaticWebAssetEndpoints)" />
132+
<StaticWebAssetEndpoint Include="@(_MissingReferencedProjectBuildStaticWebAssetEndpoints)" />
118133

119134
<StaticWebAssetDiscoveryPattern
120135
Include="@(_ReferencedProjectBuildStaticWebAssetsItems)"
121136
Condition="'%(_ReferencedProjectBuildStaticWebAssetsItems.ResultType)' == 'StaticWebAssetDiscoveryPattern'"
122137
KeepMetadata="@(_StaticWebAssetDiscoveryPatternCanonicalMetadata)" />
138+
123139
</ItemGroup>
124140

125141
</Target>

src/StaticWebAssetsSdk/Tasks/ApplyCompressionNegotiation.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public override bool Execute()
3131
var compressedAssets = assetsById.Values.Where(a => a.AssetTraitName == "Content-Encoding").ToList();
3232
var updatedEndpoints = new List<StaticWebAssetEndpoint>();
3333

34+
var preservedEndpoints = new Dictionary<(string,string), StaticWebAssetEndpoint>();
35+
3436
// Add response headers to compressed endpoints
3537
foreach (var compressedAsset in compressedAssets)
3638
{
@@ -122,11 +124,19 @@ public override bool Execute()
122124
// the ItemSpec, we want to add the original as well so that it gets re-added.
123125
// The endpoint pointing to the uncompressed asset doesn't have a Content-Encoding selector and
124126
// will use the default "identity" encoding during content negotiation.
125-
updatedEndpoints.Add(relatedEndpointCandidate);
127+
if(!preservedEndpoints.ContainsKey((relatedEndpointCandidate.Route, relatedEndpointCandidate.AssetFile)))
128+
{
129+
preservedEndpoints.Add(
130+
(relatedEndpointCandidate.Route, relatedEndpointCandidate.AssetFile),
131+
relatedEndpointCandidate);
132+
}
126133
}
127134
}
128135
}
129136

137+
// Add the preserved endpoints to the list of updated endpoints.
138+
updatedEndpoints.AddRange(preservedEndpoints.Values);
139+
130140
// Before we return the updated endpoints we need to capture any other endpoint whose asset is not associated
131141
// with the compressed asset. This is because we are going to remove the endpoints from the associated item group
132142
// and the route is the ItemSpec, so it will cause those endpoints to be removed.

src/StaticWebAssetsSdk/Tasks/ComputeStaticWebAssetsForCurrentProject.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ComputeStaticWebAssetsForCurrentProject : Task
1616
[Required]
1717
public string AssetKind { get; set; }
1818

19+
public bool IncludeReferenceAssets { get; set; }
20+
1921
[Required]
2022
public string Source { get; set; }
2123

@@ -50,7 +52,7 @@ public override bool Execute()
5052
}
5153
}
5254

53-
if (!selected.IsForReferencedProjectsOnly())
55+
if (!selected.IsForReferencedProjectsOnly() || IncludeReferenceAssets)
5456
{
5557
resultAssets.Add(selected);
5658
}

src/StaticWebAssetsSdk/Tasks/DefineStaticWebAssetEndpoints.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public override bool Execute()
5151
{
5252
var asset = kvp.Value;
5353
StaticWebAssetEndpoint endpoint = null;
54-
if (!asset.IsDiscovered() && !asset.IsComputed())
55-
{
56-
// If the asset is not for the current project, we skip it.
57-
// Package endpoints are already defined in the package Endpoints.props file.
58-
// Referenced project endpoints are retrieved from the call to GetCurrentProjectBuildStaticWebAssetItems and
59-
// GetCurrentProjectPublishStaticWebAssetItems respectively.
60-
Log.LogMessage(MessageImportance.Low, $"Skipping asset {asset.Identity} because it is not for the current project.");
61-
continue;
62-
}
54+
//if (!asset.IsDiscovered() && !asset.IsComputed())
55+
//{
56+
// // If the asset is not for the current project, we skip it.
57+
// // Package endpoints are already defined in the package Endpoints.props file.
58+
// // Referenced project endpoints are retrieved from the call to GetCurrentProjectBuildStaticWebAssetItems and
59+
// // GetCurrentProjectPublishStaticWebAssetItems respectively.
60+
// Log.LogMessage(MessageImportance.Low, $"Skipping asset {asset.Identity} because it is not for the current project.");
61+
// continue;
62+
//}
6363

6464
// StaticWebAssets has this behavior where the base path for an asset only gets applied if the asset comes from a
6565
// package or a referenced project and ignored if it comes from the current project.

src/WasmSdk/targets/Microsoft.NET.Sdk.WebAssembly.6_0.temp.targets

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
AssetTraitValue="manifest"
8484
CopyToOutputDirectory="PreserveNewest"
8585
CopyToPublishDirectory="Never"
86-
ContentRoot="$(OutDir)wwwroot"
86+
ContentRoot="$(IntermediateOutputPath)"
8787
BasePath="$(StaticWebAssetBasePath)"
8888
>
8989
<Output TaskParameter="Assets" ItemName="_PatchBuildWasmBootJsonStaticWebAsset" />
@@ -161,6 +161,20 @@
161161
</ItemGroup>
162162
</Target>
163163

164+
<Target Name="_DefineEndpointsForWasmExtensions" AfterTargets="ComputeWasmExtensions">
165+
<DefineStaticWebAssetEndpoints
166+
CandidateAssets="@(_BlazorExtensionsCandidatesForPublish)"
167+
ExistingEndpoints="@(StaticWebAssetEndpoint)"
168+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
169+
>
170+
<Output TaskParameter="Endpoints" ItemName="_WasmExtensionStaticWebAssetEndpoint" />
171+
</DefineStaticWebAssetEndpoints>
172+
173+
<ItemGroup>
174+
<StaticWebAssetEndpoint Include="@(_WasmExtensionStaticWebAssetEndpoint)" />
175+
</ItemGroup>
176+
</Target>
177+
164178
<Target Name="_DefinePublishBootJsonEndpoint" AfterTargets="_AddPublishWasmBootJsonToStaticWebAssets">
165179
<PropertyGroup>
166180
<_PublishWasmBootJsonPath>@(_PublishWasmBootJson->'%(FullPath)')</_PublishWasmBootJsonPath>

src/WasmSdk/targets/Microsoft.NET.Sdk.WebAssembly.9_0.temp.targets

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
AssetTraitValue="manifest"
8686
CopyToOutputDirectory="PreserveNewest"
8787
CopyToPublishDirectory="Never"
88-
ContentRoot="$(OutDir)wwwroot"
88+
ContentRoot="$(IntermediateOutputPath)"
8989
BasePath="$(StaticWebAssetBasePath)"
9090
>
9191
<Output TaskParameter="Assets" ItemName="_PatchBuildWasmBootJsonStaticWebAsset" />
@@ -163,6 +163,20 @@
163163
</ItemGroup>
164164
</Target>
165165

166+
<Target Name="_DefineEndpointsForWasmExtensions" AfterTargets="ComputeWasmExtensions">
167+
<DefineStaticWebAssetEndpoints
168+
CandidateAssets="@(_BlazorExtensionsCandidatesForPublish)"
169+
ExistingEndpoints="@(StaticWebAssetEndpoint)"
170+
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
171+
>
172+
<Output TaskParameter="Endpoints" ItemName="_WasmExtensionStaticWebAssetEndpoint" />
173+
</DefineStaticWebAssetEndpoints>
174+
175+
<ItemGroup>
176+
<StaticWebAssetEndpoint Include="@(_WasmExtensionStaticWebAssetEndpoint)" />
177+
</ItemGroup>
178+
</Target>
179+
166180
<Target Name="_DefinePublishBootJsonEndpoint" AfterTargets="_AddPublishWasmBootJsonToStaticWebAssets">
167181
<PropertyGroup>
168182
<_PublishWasmBootJsonPath>@(_PublishWasmBootJson->'%(FullPath)')</_PublishWasmBootJsonPath>

test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void JsModules_CanCustomizeBlazorInitialization()
215215

216216
var publish = new PublishCommand(ProjectDirectory);
217217
publish.WithWorkingDirectory(ProjectDirectory.TestRoot);
218-
var publishResult = publish.Execute();
218+
var publishResult = publish.Execute("/bl");
219219
publishResult.Should().Pass();
220220

221221
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
@@ -282,7 +282,7 @@ public void JsModules_Hosted_CanCustomizeBlazorInitialization()
282282

283283
var publish = new PublishCommand(ProjectDirectory, "blazorhosted");
284284
publish.WithWorkingDirectory(ProjectDirectory.TestRoot);
285-
var publishResult = publish.Execute();
285+
var publishResult = publish.Execute("/bl");
286286
publishResult.Should().Pass();
287287

288288
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();

test/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AspNetSdkBaselineTest : AspNetSdkTest
1717

1818
private string _baselinesFolder;
1919

20-
#if !GENERATE_SWA_BASELINES
20+
#if GENERATE_SWA_BASELINES
2121
public static bool GenerateBaselines = true;
2222
#else
2323
public static bool GenerateBaselines = bool.TryParse(Environment.GetEnvironmentVariable("ASPNETCORE_TEST_BASELINES"), out var result) && result;

0 commit comments

Comments
 (0)