diff --git a/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets b/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets index 3fdb67030110..b647bd15d784 100644 --- a/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets +++ b/src/BlazorWasmSdk/Targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets @@ -86,6 +86,10 @@ Copyright (c) .NET Foundation. All rights reserved. GenerateBuildBlazorBootExtensionJson; + + $(ResolveHtmlAssetPlaceholdersPublishConfigurationDependsOn); + _ReplaceFingerprintedBlazorJsForPublish + $(ResolvePublishRelatedStaticWebAssetsDependsOn); _ReplaceFingerprintedBlazorJsForPublish @@ -109,7 +113,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + <_BlazorJSFile Include="$(BlazorWebAssemblyJSPath)" /> <_BlazorJSFile Include="$(BlazorWebAssemblyJSMapPath)" Condition="Exists('$(BlazorWebAssemblyJSMapPath)')" /> @@ -125,14 +129,20 @@ Copyright (c) .NET Foundation. All rights reserved. Code="RAZORSDK1007" Condition="'@(_BlazorJSFile->Count())' == '0'" /> + + + + <_BlazorJSFileAssetKindBuild>All + <_BlazorJSFileAssetKindBuild Condition="'$(BlazorFingerprintBlazorJs)' == 'true'">Build + - + <_BlazorJSFileNames>;@(_BlazorJSFile->'%(FileName)'); @@ -178,7 +188,7 @@ Copyright (c) .NET Foundation. All rights reserved. FingerprintPatterns="@(_BlazorJSFingerprintPattern)" SourceId="$(PackageId)" SourceType="Computed" - AssetKind="All" + AssetKind="Publish" AssetMergeSource="$(StaticWebAssetMergeTarget)" AssetRole="Primary" AssetTraitName="WasmResource" @@ -197,23 +207,9 @@ Copyright (c) .NET Foundation. All rights reserved. > - - <_BlazorJSJSStaticWebAssetFullPath>@(_BlazorJSJSStaticWebAsset->'%(FullPath)') - - - <_BlazorJSJSStaticWebAsset Include="@(StaticWebAsset)" Condition="'%(AssetTraitName)' == 'Content-Encoding' and '%(RelatedAsset)' == '$(_BlazorJSJSStaticWebAssetFullPath)'" /> - - - - + - - diff --git a/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.HtmlAssetPlaceholders.targets b/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.HtmlAssetPlaceholders.targets index 6f2f36938eb4..a6c355d0bc32 100644 --- a/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.HtmlAssetPlaceholders.targets +++ b/src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.HtmlAssetPlaceholders.targets @@ -145,7 +145,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + <_PublishHtmlAssetPlaceholdersPath>$([MSBuild]::NormalizeDirectory($(_StaticWebAssetsIntermediateOutputPath), 'htmlassetplaceholders', 'publish')) diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs index 6b26bd237940..cab0eb56e6e1 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs @@ -1612,6 +1612,16 @@ public class TestReference fileInWwwroot.Should().Exist(); } + [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [InlineData("")] + [InlineData("/p:BlazorFingerprintBlazorJs=false")] + public void Publish_BlazorWasmReferencedByAspNetCoreServer(string publishArg) + { + var testInstance = CreateAspNetSdkTestAsset("BlazorWasmReferencedByAspNetCoreServer"); + var publishCommand = CreatePublishCommand(testInstance, "Server"); + ExecuteCommand(publishCommand, publishArg).Should().Pass(); + } + private void VerifyTypeGranularTrimming(string blazorPublishDirectory) { VerifyAssemblyHasTypes(Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.AspNetCore.Components.wasm"), new[] { diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/BlazorWasmReferencedByAspNetCoreServer.slnx b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/BlazorWasmReferencedByAspNetCoreServer.slnx new file mode 100644 index 000000000000..3e2628def731 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/BlazorWasmReferencedByAspNetCoreServer.slnx @@ -0,0 +1,4 @@ + + + + diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/App.razor b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/App.razor new file mode 100644 index 000000000000..e9ec234d512a --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/App.razor @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Client.csproj b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Client.csproj new file mode 100644 index 000000000000..d66142167861 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Client.csproj @@ -0,0 +1,20 @@ + + + + net10.0 + enable + enable + true + service-worker-assets.js + + + + + + + + + + + + diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Program.cs b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Program.cs new file mode 100644 index 000000000000..121b10340b73 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/Program.cs @@ -0,0 +1,11 @@ +using Client; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; + +var builder = WebAssemblyHostBuilder.CreateDefault(args); +builder.RootComponents.Add("#app"); +builder.RootComponents.Add("head::after"); + +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); + +await builder.Build().RunAsync(); diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/_Imports.razor b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/_Imports.razor new file mode 100644 index 000000000000..08a3968fb7a0 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/_Imports.razor @@ -0,0 +1,9 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.AspNetCore.Components.WebAssembly.Http +@using Microsoft.JSInterop +@using Client diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/wwwroot/index.html b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/wwwroot/index.html new file mode 100644 index 000000000000..de0f63c833a0 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Client/wwwroot/index.html @@ -0,0 +1,37 @@ + + + + + + + Client + + + + + + + + + + + + + +
+ + + + +
+
+ +
+ An unhandled error has occurred. + Reload + 🗙 +
+ + + + diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Program.cs b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Program.cs new file mode 100644 index 000000000000..675fa26b2d66 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Program.cs @@ -0,0 +1,18 @@ +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddOpenApi(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); + app.MapOpenApi(); +} + +app.UseHttpsRedirection(); + +app.MapStaticAssets(); +app.MapFallbackToFile("index.html"); + +app.Run(); diff --git a/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Server.csproj b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Server.csproj new file mode 100644 index 000000000000..d18a448b6fa0 --- /dev/null +++ b/test/TestAssets/TestProjects/BlazorWasmReferencedByAspNetCoreServer/Server/Server.csproj @@ -0,0 +1,18 @@ + + + + net10.0 + enable + enable + + + + + + + + + + + +