Skip to content
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

Add package for consuming Blazor framework assets #58721

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.OpenAp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.App.SourceGenerators", "src\Framework\AspNetCoreAnalyzers\src\SourceGenerators\Microsoft.AspNetCore.App.SourceGenerators.csproj", "{C3928C15-1836-46DB-A09D-9EFBCCA33E08}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{2B858B82-5F0B-4A24-B3C0-5E99149F70D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.App.Internal.Assets", "src\Assets\Microsoft.AspNetCore.App.Internal.Assets.csproj", "{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -10977,6 +10981,22 @@ Global
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x64.Build.0 = Release|Any CPU
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.ActiveCfg = Release|Any CPU
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.Build.0 = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.ActiveCfg = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.Build.0 = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.ActiveCfg = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.Build.0 = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.ActiveCfg = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.Build.0 = Debug|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.Build.0 = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.ActiveCfg = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.Build.0 = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.ActiveCfg = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.Build.0 = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.ActiveCfg = Release|Any CPU
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -11874,6 +11894,8 @@ Global
{B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC} = {2299CCD8-8F9C-4F2B-A633-9BF4DA81022B}
{B9BBC1A8-7F58-4F43-94C3-5F3CB125CEF7} = {B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC}
{C3928C15-1836-46DB-A09D-9EFBCCA33E08} = {B5D98AEB-9409-4280-8225-9C1EC6A791B2}
{2B858B82-5F0B-4A24-B3C0-5E99149F70D6} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62} = {2B858B82-5F0B-4A24-B3C0-5E99149F70D6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
Expand Down
2 changes: 2 additions & 0 deletions eng/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
$(RepoRoot)src\Framework\App.Ref.Internal\src\Microsoft.AspNetCore.App.Ref.Internal.csproj;
$(RepoRoot)src\Framework\AspNetCoreAnalyzers\test\Microsoft.AspNetCore.App.Analyzers.Test.csproj;
$(RepoRoot)src\Framework\test\Microsoft.AspNetCore.App.UnitTests.csproj;
$(RepoRoot)src\Assets\**\*.*proj;
$(RepoRoot)src\Caching\**\*.*proj;
$(RepoRoot)src\DefaultBuilder\**\*.*proj;
$(RepoRoot)src\Features\JsonPatch\**\*.*proj;
Expand Down Expand Up @@ -200,6 +201,7 @@
$(RepoRoot)**\obj\**\*;"
Condition=" '$(BuildMainlyReferenceProviders)' != 'true' " />
<DotNetProjects Include="
$(RepoRoot)src\Assets\**\*.*proj;
$(RepoRoot)src\Caching\**\src\*.csproj;
$(RepoRoot)src\DefaultBuilder\**\src\*.csproj;
$(RepoRoot)src\Features\JsonPatch\**\src\*.csproj;
Expand Down
1 change: 1 addition & 0 deletions eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-->
<Project>
<ItemGroup>
<ProjectReferenceProvider Include="Microsoft.AspNetCore.App.Internal.Assets" ProjectPath="$(RepoRoot)src\Assets\Microsoft.AspNetCore.App.Internal.Assets.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.SqlServer" ProjectPath="$(RepoRoot)src\Caching\SqlServer\src\Microsoft.Extensions.Caching.SqlServer.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.StackExchangeRedis" ProjectPath="$(RepoRoot)src\Caching\StackExchangeRedis\src\Microsoft.Extensions.Caching.StackExchangeRedis.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore" ProjectPath="$(RepoRoot)src\DefaultBuilder\src\Microsoft.AspNetCore.csproj" />
Expand Down
1 change: 1 addition & 0 deletions eng/ShippingAssemblies.props
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<AspNetCoreShippingAssembly Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" />
<AspNetCoreShippingAssembly Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<AspNetCoreShippingAssembly Include="Microsoft.Extensions.Features" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.App.Internal.Assets" />
<AspNetCoreShippingAssembly Include="Microsoft.Extensions.Caching.SqlServer" />
<AspNetCoreShippingAssembly Include="Microsoft.Extensions.Caching.StackExchangeRedis" />
<AspNetCoreShippingAssembly Include="Microsoft.AspNetCore.JsonPatch" />
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/npm/update-dependency-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function applyPackageVersion(packagesToPack, defaultPackageVersion) {
renames.push([`${packagePath}.bak`, packagePath]);

process.chdir(packageDir);
execSync(`npm version ${packageVersion} --no-git-tag-version`, { stdio: 'inherit' });
execSync(`npm version ${packageVersion} --no-git-tag-version --allow-same-version`, { stdio: 'inherit' });
process.chdir(currentDir);
console.log(`Applied version ${packageVersion} to ${packageName} in ${packageDir}...`);
}
Expand Down
10 changes: 10 additions & 0 deletions eng/tools/GenerateFiles/Directory.Build.targets.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
TargetFramework="${DefaultNetCoreTargetFramework}"
Condition="'@(KnownWebAssemblySdkPack->Count())' != '0' AND
!(@(KnownWebAssemblySdkPack->AnyHaveMetadataValue('TargetFramework', '${DefaultNetCoreTargetFramework}')))" />
<KnownAspNetCorePack
Include="@(KnownAspNetCorePack->WithMetadataValue('TargetFramework', 'net9.0'))"
TargetFramework="${DefaultNetCoreTargetFramework}"
Condition="'@(KnownAspNetCorePack->Count())' != '0' AND
!(@(KnownAspNetCorePack->AnyHaveMetadataValue('TargetFramework', '${DefaultNetCoreTargetFramework}')))" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -95,6 +100,11 @@
Condition=" '%(TargetFramework)' == '${DefaultNetCoreTargetFramework}' ">${MicrosoftNETCoreAppRuntimeVersion}</WebAssemblySdkPackVersion>
</KnownWebAssemblySdkPack>

<KnownAspNetCorePack Update="Microsoft.AspNetCore.App.Internal.Assets">
<AspNetCorePackVersion
Condition=" '%(TargetFramework)' == '${DefaultNetCoreTargetFramework}' ">${MicrosoftAspNetCoreAppRuntimeVersion}</AspNetCorePackVersion>
</KnownAspNetCorePack>

<KnownCrossgen2Pack Update="Microsoft.NETCore.App.Crossgen2" Condition=" '$(DotNetBuildSourceOnly)' == 'true' ">
<Crossgen2PackVersion
Condition=" '%(TargetFramework)' == '${DefaultNetCoreTargetFramework}' ">${MicrosoftNETCoreAppRuntimeVersion}</Crossgen2PackVersion>
Expand Down
51 changes: 51 additions & 0 deletions src/Assets/Microsoft.AspNetCore.App.Internal.Assets.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<Description>ASP.NET Core static framework assets</Description>
<PackageId>Microsoft.AspNetCore.App.Internal.Assets</PackageId>
<IsPackable>true</IsPackable>
<OutputType>Library</OutputType>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
<ImplicitUsings>disable</ImplicitUsings>

<!-- The package doesn't produce any lib or ref assemblies -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>

<PropertyGroup>
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Debug'">$(RepoRoot)src\Components\Web.JS\dist\Debug</_BlazorJSContentRoot>
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</_BlazorJSContentRoot>
</PropertyGroup>

<ItemGroup>
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.web.js" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.server.js" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.webassembly.js" />

<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.web.js.map" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.server.js.map" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.webassembly.js.map" />
</ItemGroup>

<ItemGroup>
<None Include="build\*" Pack="true" PackagePath="%(Identity)" />
<None Include="buildMultiTargeting\*" Pack="true" PackagePath="%(Identity)" />
<None Include="buildTransitive\*" Pack="true" PackagePath="%(Identity)" />
<None Include="@(_BlazorJSFile)" Pack="true" PackagePath="_framework\%(FileName)%(Extension)" />
</ItemGroup>

<Target Name="_CheckBlazorJSPath" AfterTargets="ResolveProjectReferences">
<ItemGroup>
<_MissingBlazorJSFile Include="@(_BlazorJSFile)" Condition="!EXISTS('%(_BlazorJSFile.FullPath)')" />
</ItemGroup>

<Error
Condition="'@(_MissingBlazorJSFile)' != ''"
Text="'%(_MissingBlazorJSFile.Identity)' does not exist. Run 'npm run build' in the repo root to generate the file." />
</Target>

</Project>
3 changes: 3 additions & 0 deletions src/Assets/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
SET RepoRoot=%~dp0..\..
%RepoRoot%\eng\build.cmd -projects %~dp0**\*.*proj %*
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
68 changes: 68 additions & 0 deletions src/Assets/build/Microsoft.AspNetCore.App.Internal.Assets.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Project>
<PropertyGroup>
<ResolveStaticWebAssetsInputsDependsOn>
$(ResolveStaticWebAssetsInputsDependsOn);
_AddBlazorFrameworkStaticWebAssets;
</ResolveStaticWebAssetsInputsDependsOn>
</PropertyGroup>

<PropertyGroup>
<BlazorFrameworkStaticWebAssetRoot Condition="'$(BlazorFrameworkStaticWebAssetRoot)' == ''">$(MSBuildThisFileDirectory)..\_framework</BlazorFrameworkStaticWebAssetRoot>
</PropertyGroup>

<Target Name="_AddBlazorFrameworkStaticWebAssets" Condition="'$(OutputType)' == 'Exe'">
<ItemGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true'">
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.web.js" />
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.server.js" />
</ItemGroup>

<ItemGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' AND '$(UseBlazorFrameworkDebugAssets)' == 'true'">
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.web.js.map" />
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.server.js.map" />
</ItemGroup>

<PropertyGroup>
<_IncludeAssetsInBlazorWebAssemblyProject Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' AND '$(StaticWebAssetProjectMode)' != 'Default'">true</_IncludeAssetsInBlazorWebAssemblyProject>
</PropertyGroup>

<ItemGroup Condition="'$(_IncludeAssetsInBlazorWebAssemblyProject)' == 'true'">
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.webassembly.js" />
</ItemGroup>

<ItemGroup Condition="'$(_IncludeAssetsInBlazorWebAssemblyProject)' == 'true' AND '$(UseBlazorFrameworkDebugAssets)' == 'true'">
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.webassembly.js.map" />
</ItemGroup>

<ItemGroup>
<_FrameworkStaticWebAssetCandidate>
<RelativePath>_framework\%(FileName)%(Extension)</RelativePath>
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
</_FrameworkStaticWebAssetCandidate>
</ItemGroup>

<DefineStaticWebAssets
Condition="'@(_FrameworkStaticWebAssetCandidate->Count())' != '0'"
CandidateAssets="@(_FrameworkStaticWebAssetCandidate)"
SourceId="Microsoft.AspNetCore.App.Internal.Assets"
SourceType="Discovered"
AssetKind="All"
FingerprintCandidates="true"
BasePath="$(StaticWebAssetBasePath)">
<Output TaskParameter="Assets" ItemName="_FrameworkStaticWebAsset" />
</DefineStaticWebAssets>

<DefineStaticWebAssetEndpoints
Condition="'@(_FrameworkStaticWebAsset)' != ''"
CandidateAssets="@(_FrameworkStaticWebAsset)"
ExistingEndpoints=""
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)">
<Output TaskParameter="Endpoints" ItemName="_FrameworkStaticAssetEndpoint" />
</DefineStaticWebAssetEndpoints>

<ItemGroup>
<StaticWebAsset Include="@(_FrameworkStaticWebAsset)" />
<StaticWebAssetEndpoint Include="@(_FrameworkStaticAssetEndpoint)" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\buildTransitive\Microsoft.AspNetCore.App.Internal.Assets.targets"/>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)..\build\Microsoft.AspNetCore.App.Internal.Assets.targets"/>
</Project>
3 changes: 2 additions & 1 deletion src/Components/Components.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"projects": [
"src\\Analyzers\\Microsoft.AspNetCore.Analyzer.Testing\\src\\Microsoft.AspNetCore.Analyzer.Testing.csproj",
"src\\Antiforgery\\src\\Microsoft.AspNetCore.Antiforgery.csproj",
"src\\Assets\\Microsoft.AspNetCore.App.Internal.Assets.csproj",
"src\\Components\\Analyzers\\src\\Microsoft.AspNetCore.Components.Analyzers.csproj",
"src\\Components\\Analyzers\\test\\Microsoft.AspNetCore.Components.Analyzers.Tests.csproj",
"src\\Components\\Authorization\\src\\Microsoft.AspNetCore.Components.Authorization.csproj",
Expand Down Expand Up @@ -156,4 +157,4 @@
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj"
]
}
}
}
8 changes: 8 additions & 0 deletions src/Components/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
</PropertyGroup>

<!-- Workaround to add Blazor framework static assets without requiring a package reference -->
<PropertyGroup>
<BlazorFrameworkStaticWebAssetRoot Condition="'$(Configuration)' == 'Debug'">$(RepoRoot)src\Components\Web.JS\dist\Debug</BlazorFrameworkStaticWebAssetRoot>
<BlazorFrameworkStaticWebAssetRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</BlazorFrameworkStaticWebAssetRoot>
</PropertyGroup>

<Import Project="$(RepoRoot)\src\Assets\build\Microsoft.AspNetCore.App.Internal.Assets.targets" />

</Project>
18 changes: 0 additions & 18 deletions src/Components/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<Project>
<PropertyGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'">
<BlazorWebAssemblyJSPath
Condition=" '$(Configuration)' == 'Debug' ">$(RepoRoot)src\Components\Web.JS\dist\Debug\blazor.webassembly.js</BlazorWebAssemblyJSPath>
<BlazorWebAssemblyJSPath
Condition=" '$(Configuration)' != 'Debug' ">$(RepoRoot)src\Components\Web.JS\dist\Release\blazor.webassembly.js</BlazorWebAssemblyJSPath>
<BlazorWebAssemblyJSMapPath>$(BlazorWebAssemblyJSPath).map</BlazorWebAssemblyJSMapPath>

<_BlazorDevServerPath>$(ArtifactsDir)bin/Microsoft.AspNetCore.Components.WebAssembly.DevServer/$(Configuration)/$(DefaultNetCoreTargetFramework)/blazor-devserver.dll</_BlazorDevServerPath>
<RunCommand>dotnet</RunCommand>
<_RunExtraArguments Condition="'$(WasmEnableThreads)' == 'true'">--apply-cop-headers</_RunExtraArguments>
<RunArguments>exec &quot;$(_BlazorDevServerPath)&quot; --applicationpath &quot;$(TargetPath)&quot; $(_RunExtraArguments) $(AdditionalRunArguments)</RunArguments>
</PropertyGroup>

<Target Name="_CheckBlazorWebAssemblyJSPath" AfterTargets="ResolveProjectReferences"
Condition=" '$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' AND !EXISTS('$(BlazorWebAssemblyJSPath)') ">
<Error Text="'$(BlazorWebAssemblyJSPath)' does not exist. Enable NodeJS to build this project." />
</Target>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
using Microsoft.AspNetCore.Components.Endpoints.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using static Microsoft.AspNetCore.Internal.LinkerFlags;

Expand Down Expand Up @@ -180,7 +177,6 @@ private void UpdateEndpoints()
private void AddBlazorWebEndpoints(List<Endpoint> endpoints)
{
List<EndpointBuilder> blazorWebEndpoints = [
..GetBlazorWebJsEndpoint(_endpointRouteBuilder),
OpaqueRedirection.GetBlazorOpaqueRedirectionEndpoint()];

foreach (var endpoint in blazorWebEndpoints)
Expand All @@ -199,56 +195,6 @@ private void AddBlazorWebEndpoints(List<Endpoint> endpoints)
}
}

private static IEnumerable<EndpointBuilder> GetBlazorWebJsEndpoint(IEndpointRouteBuilder endpoints)
{
var app = endpoints.CreateApplicationBuilder();

var options = new StaticFileOptions
{
FileProvider = new ManifestEmbeddedFileProvider(typeof(RazorComponentsEndpointRouteBuilderExtensions).Assembly),
OnPrepareResponse = CacheHeaderSettings.SetCacheHeaders
};

app.Use(next => context =>
{
// Set endpoint to null so the static files middleware will handle the request.
context.SetEndpoint(null);

return next(context);
});

app.UseStaticFiles(options);

var requestDelegate = app.Build();

var blazorWebJsBuilder = new RouteEndpointBuilder(
requestDelegate,
RoutePatternFactory.Parse("/_framework/blazor.web.js"),
int.MinValue)
{
DisplayName = "Blazor web static files"
};

var allowedHttpMethods = new HttpMethodMetadata([HttpMethods.Get, HttpMethods.Head]);
blazorWebJsBuilder.Metadata.Add(allowedHttpMethods);

#if !DEBUG
return [blazorWebJsBuilder];
#else
// We only need to serve the sourcemap when working on the framework, not in the distributed packages
var blazorWebJsDebugBuilder = new RouteEndpointBuilder(
requestDelegate,
RoutePatternFactory.Parse("/_framework/blazor.web.js.map"),
int.MinValue)
{
DisplayName = "Blazor web static files sourcemap"
};
blazorWebJsDebugBuilder.Metadata.Add(allowedHttpMethods);

return [blazorWebJsBuilder, blazorWebJsDebugBuilder];
#endif
}

public void OnHotReloadClearCache(Type[]? types)
{
lock (_lock)
Expand Down
3 changes: 0 additions & 3 deletions src/Components/Endpoints/src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
<!-- Workaround target import for project references to Microsoft.Extensions.FileProviders.Embedded -->
<Import
Project="$(RepoRoot)src\FileProviders\Embedded\src\build\netstandard2.0\Microsoft.Extensions.FileProviders.Embedded.targets" />
</Project>
Loading
Loading