Skip to content

Commit 1e5a9cf

Browse files
committed
Fix local development scenarios
1 parent ef6fd02 commit 1e5a9cf

File tree

22 files changed

+78
-166
lines changed

22 files changed

+78
-166
lines changed

AspNetCore.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.OpenAp
18161816
EndProject
18171817
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}"
18181818
EndProject
1819+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{2B858B82-5F0B-4A24-B3C0-5E99149F70D6}"
1820+
EndProject
1821+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Assets.Pack", "src\Assets\Pack\Microsoft.AspNetCore.Assets.Pack.csproj", "{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}"
1822+
EndProject
18191823
Global
18201824
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18211825
Debug|Any CPU = Debug|Any CPU
@@ -10977,6 +10981,22 @@ Global
1097710981
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x64.Build.0 = Release|Any CPU
1097810982
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.ActiveCfg = Release|Any CPU
1097910983
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.Build.0 = Release|Any CPU
10984+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10985+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
10986+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.ActiveCfg = Debug|Any CPU
10987+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.Build.0 = Debug|Any CPU
10988+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.ActiveCfg = Debug|Any CPU
10989+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.Build.0 = Debug|Any CPU
10990+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.ActiveCfg = Debug|Any CPU
10991+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.Build.0 = Debug|Any CPU
10992+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
10993+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.Build.0 = Release|Any CPU
10994+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.ActiveCfg = Release|Any CPU
10995+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.Build.0 = Release|Any CPU
10996+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.ActiveCfg = Release|Any CPU
10997+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.Build.0 = Release|Any CPU
10998+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.ActiveCfg = Release|Any CPU
10999+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.Build.0 = Release|Any CPU
1098011000
EndGlobalSection
1098111001
GlobalSection(SolutionProperties) = preSolution
1098211002
HideSolutionNode = FALSE
@@ -11874,6 +11894,8 @@ Global
1187411894
{B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC} = {2299CCD8-8F9C-4F2B-A633-9BF4DA81022B}
1187511895
{B9BBC1A8-7F58-4F43-94C3-5F3CB125CEF7} = {B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC}
1187611896
{C3928C15-1836-46DB-A09D-9EFBCCA33E08} = {B5D98AEB-9409-4280-8225-9C1EC6A791B2}
11897+
{2B858B82-5F0B-4A24-B3C0-5E99149F70D6} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
11898+
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62} = {2B858B82-5F0B-4A24-B3C0-5E99149F70D6}
1187711899
EndGlobalSection
1187811900
GlobalSection(ExtensibilityGlobals) = postSolution
1187911901
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Assets/Pack/Microsoft.AspNetCore.Assets.Pack.proj renamed to src/Assets/Pack/Microsoft.AspNetCore.Assets.Pack.csproj

Lines changed: 33 additions & 4 deletions
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.Web">
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
@@ -9,6 +9,7 @@
99
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
1010
<IncludeBuildOutput>false</IncludeBuildOutput>
1111
<IncludeSymbols>false</IncludeSymbols>
12+
<ImplicitUsings>disable</ImplicitUsings>
1213

1314
<!-- The package doesn't produce any lib or ref assemblies -->
1415
<NoWarn>$(NoWarn);NU5128</NoWarn>
@@ -19,6 +20,7 @@
1920
<StaticWebAssetsDisableProjectBuildPropsFileGeneration>true</StaticWebAssetsDisableProjectBuildPropsFileGeneration>
2021
<StaticWebAssetsDisableProjectBuildMultiTargetingPropsFileGeneration>true</StaticWebAssetsDisableProjectBuildMultiTargetingPropsFileGeneration>
2122
<StaticWebAssetsDisableProjectBuildTransitivePropsFileGeneration>true</StaticWebAssetsDisableProjectBuildTransitivePropsFileGeneration>
23+
<StaticWebAssetsGetBuildAssetsTargets>_GetFrameworkBuildAssets</StaticWebAssetsGetBuildAssetsTargets>
2224
</PropertyGroup>
2325

2426
<ItemGroup>
@@ -55,6 +57,36 @@
5557

5658
</Target>
5759

60+
<Target Name="_GetFrameworkBuildAssets" Returns="@(ReferenceAsset)">
61+
62+
<ItemGroup>
63+
<_ReferenceAssetCandidates Include="@(_BlazorJSFile)" />
64+
<_ReferenceAssetCandidates>
65+
<RelativePath>$(StaticWebAssetBasePath)/%(FileName)%(Extension)</RelativePath>
66+
<ContentRoot>$([System.IO.Path]::GetFullPath($([System.IO.Path]::GetDirectoryName('%(Identity)'))))</ContentRoot>
67+
</_ReferenceAssetCandidates>
68+
</ItemGroup>
69+
70+
<DefineStaticWebAssets
71+
Condition="'@(_ReferenceAssetCandidates->Count())' != '0'"
72+
CandidateAssets="@(_ReferenceAssetCandidates)"
73+
SourceId="$(PackageId)"
74+
SourceType="Project"
75+
AssetKind="All"
76+
FingerprintCandidates="true"
77+
BasePath="/"
78+
>
79+
<Output TaskParameter="Assets" ItemName="ReferenceAsset" />
80+
</DefineStaticWebAssets>
81+
82+
<ItemGroup>
83+
<ReferenceAsset>
84+
<ResultType>StaticWebAsset</ResultType>
85+
</ReferenceAsset>
86+
</ItemGroup>
87+
88+
</Target>
89+
5890
<Target Name="_GenerateFrameworkPackItems" BeforeTargets="GenerateStaticWebAssetsPackFiles">
5991
<ItemGroup>
6092
<_AssetCandidates Include="@(_BlazorJSFile)" />
@@ -110,7 +142,4 @@
110142

111143
</Target>
112144

113-
<Target Name="CreateManifestResourceNames" />
114-
<Target Name="CoreCompile" />
115-
116145
</Project>

src/Components/Components.slnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"projects": [
55
"src\\Analyzers\\Microsoft.AspNetCore.Analyzer.Testing\\src\\Microsoft.AspNetCore.Analyzer.Testing.csproj",
66
"src\\Antiforgery\\src\\Microsoft.AspNetCore.Antiforgery.csproj",
7+
"src\\Assets\\Pack\\Microsoft.AspNetCore.Assets.Pack.csproj",
78
"src\\Components\\Analyzers\\src\\Microsoft.AspNetCore.Components.Analyzers.csproj",
89
"src\\Components\\Analyzers\\test\\Microsoft.AspNetCore.Components.Analyzers.Tests.csproj",
910
"src\\Components\\Authorization\\src\\Microsoft.AspNetCore.Components.Authorization.csproj",
@@ -156,4 +157,4 @@
156157
"src\\WebEncoders\\src\\Microsoft.Extensions.WebEncoders.csproj"
157158
]
158159
}
159-
}
160+
}
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
<Project>
2-
<PropertyGroup Condition="'$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true'">
3-
<BlazorWebAssemblyJSPath
4-
Condition=" '$(Configuration)' == 'Debug' ">$(RepoRoot)src\Components\Web.JS\dist\Debug\blazor.webassembly.js</BlazorWebAssemblyJSPath>
5-
<BlazorWebAssemblyJSPath
6-
Condition=" '$(Configuration)' != 'Debug' ">$(RepoRoot)src\Components\Web.JS\dist\Release\blazor.webassembly.js</BlazorWebAssemblyJSPath>
7-
<BlazorWebAssemblyJSMapPath>$(BlazorWebAssemblyJSPath).map</BlazorWebAssemblyJSMapPath>
8-
9-
<_BlazorDevServerPath>$(ArtifactsDir)bin/Microsoft.AspNetCore.Components.WebAssembly.DevServer/$(Configuration)/$(DefaultNetCoreTargetFramework)/blazor-devserver.dll</_BlazorDevServerPath>
10-
<RunCommand>dotnet</RunCommand>
11-
<_RunExtraArguments Condition="'$(WasmEnableThreads)' == 'true'">--apply-cop-headers</_RunExtraArguments>
12-
<RunArguments>exec &quot;$(_BlazorDevServerPath)&quot; --applicationpath &quot;$(TargetPath)&quot; $(_RunExtraArguments) $(AdditionalRunArguments)</RunArguments>
13-
</PropertyGroup>
14-
15-
<Target Name="_CheckBlazorWebAssemblyJSPath" AfterTargets="ResolveProjectReferences"
16-
Condition=" '$(UsingMicrosoftNETSdkBlazorWebAssembly)' == 'true' AND !EXISTS('$(BlazorWebAssemblyJSPath)') ">
17-
<Error Text="'$(BlazorWebAssemblyJSPath)' does not exist. Enable NodeJS to build this project." />
18-
</Target>
19-
202
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
213
</Project>

src/Components/Endpoints/src/Builder/RazorComponentEndpointDataSource.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
using Microsoft.AspNetCore.Components.Endpoints.Infrastructure;
1111
using Microsoft.AspNetCore.Http;
1212
using Microsoft.AspNetCore.Routing;
13-
using Microsoft.AspNetCore.Routing.Patterns;
14-
using Microsoft.AspNetCore.StaticFiles;
15-
using Microsoft.Extensions.FileProviders;
1613
using Microsoft.Extensions.Primitives;
1714
using static Microsoft.AspNetCore.Internal.LinkerFlags;
1815

@@ -180,7 +177,6 @@ private void UpdateEndpoints()
180177
private void AddBlazorWebEndpoints(List<Endpoint> endpoints)
181178
{
182179
List<EndpointBuilder> blazorWebEndpoints = [
183-
..GetBlazorWebJsEndpoint(_endpointRouteBuilder),
184180
OpaqueRedirection.GetBlazorOpaqueRedirectionEndpoint()];
185181

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

202-
private static IEnumerable<EndpointBuilder> GetBlazorWebJsEndpoint(IEndpointRouteBuilder endpoints)
203-
{
204-
var app = endpoints.CreateApplicationBuilder();
205-
206-
var options = new StaticFileOptions
207-
{
208-
FileProvider = new ManifestEmbeddedFileProvider(typeof(RazorComponentsEndpointRouteBuilderExtensions).Assembly),
209-
OnPrepareResponse = CacheHeaderSettings.SetCacheHeaders
210-
};
211-
212-
app.Use(next => context =>
213-
{
214-
// Set endpoint to null so the static files middleware will handle the request.
215-
context.SetEndpoint(null);
216-
217-
return next(context);
218-
});
219-
220-
app.UseStaticFiles(options);
221-
222-
var requestDelegate = app.Build();
223-
224-
var blazorWebJsBuilder = new RouteEndpointBuilder(
225-
requestDelegate,
226-
RoutePatternFactory.Parse("/_framework/blazor.web.js"),
227-
int.MinValue)
228-
{
229-
DisplayName = "Blazor web static files"
230-
};
231-
232-
var allowedHttpMethods = new HttpMethodMetadata([HttpMethods.Get, HttpMethods.Head]);
233-
blazorWebJsBuilder.Metadata.Add(allowedHttpMethods);
234-
235-
#if !DEBUG
236-
return [blazorWebJsBuilder];
237-
#else
238-
// We only need to serve the sourcemap when working on the framework, not in the distributed packages
239-
var blazorWebJsDebugBuilder = new RouteEndpointBuilder(
240-
requestDelegate,
241-
RoutePatternFactory.Parse("/_framework/blazor.web.js.map"),
242-
int.MinValue)
243-
{
244-
DisplayName = "Blazor web static files sourcemap"
245-
};
246-
blazorWebJsDebugBuilder.Metadata.Add(allowedHttpMethods);
247-
248-
return [blazorWebJsBuilder, blazorWebJsDebugBuilder];
249-
#endif
250-
}
251-
252198
public void OnHotReloadClearCache(Type[]? types)
253199
{
254200
lock (_lock)
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
<Project>
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.targets))\Directory.Build.targets" />
3-
<!-- Workaround target import for project references to Microsoft.Extensions.FileProviders.Embedded -->
4-
<Import
5-
Project="$(RepoRoot)src\FileProviders\Embedded\src\build\netstandard2.0\Microsoft.Extensions.FileProviders.Embedded.targets" />
63
</Project>

src/Components/Endpoints/src/Microsoft.AspNetCore.Components.Endpoints.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<NoWarn>$(NoWarn);CS0436</NoWarn>
1010
<IsPackable>false</IsPackable>
11-
<EmbeddedFilesManifestFileName>Microsoft.Extensions.FileProviders.Embedded.Manifest.xml</EmbeddedFilesManifestFileName>
1211
<Nullable>enable</Nullable>
1312
<DefineConstants>$(DefineConstants);COMPONENTS</DefineConstants>
1413
</PropertyGroup>
1514

16-
<!-- This workaround is required when referencing FileProviders.Embedded as a project -->
17-
<PropertyGroup>
18-
<_FileProviderTaskAssembly>$(ArtifactsDir)bin\Microsoft.Extensions.FileProviders.Embedded.Manifest.Task\$(Configuration)\netstandard2.0\Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.dll</_FileProviderTaskAssembly>
19-
</PropertyGroup>
20-
21-
<UsingTask AssemblyFile="$(_FileProviderTaskAssembly)" TaskName="Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.GenerateEmbeddedResourcesManifest" />
22-
2315
<ItemGroup>
2416
<EmbeddedResource Update="FormMapping\FormDataResources.resx" ExcludeFromManifest="true" />
2517
<EmbeddedResource Update="Resources.resx" ExcludeFromManifest="true" />
@@ -57,7 +49,6 @@
5749
<Reference Include="Microsoft.AspNetCore.Routing" />
5850
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
5951
<Reference Include="Microsoft.AspNetCore.StaticAssets" />
60-
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
6152
</ItemGroup>
6253

6354
<ItemGroup>

src/Components/Samples/BlazorUnitedApp/App.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
</head>
1616
<body>
1717
<Routes />
18-
<script src="_framework/blazor.web.js"></script>
18+
<script src="@Assets["_framework/blazor.web.js"]"></script>
1919
</body>
2020
</html>

src/Components/Server/src/Builder/ComponentEndpointConventionBuilder.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ public sealed class ComponentEndpointConventionBuilder : IHubEndpointConventionB
1111
private readonly IEndpointConventionBuilder _hubEndpoint;
1212
private readonly IEndpointConventionBuilder _disconnectEndpoint;
1313
private readonly IEndpointConventionBuilder _jsInitializersEndpoint;
14-
private readonly IEndpointConventionBuilder _blazorEndpoint;
1514

1615
internal ComponentEndpointConventionBuilder(
1716
IEndpointConventionBuilder hubEndpoint,
1817
IEndpointConventionBuilder disconnectEndpoint,
19-
IEndpointConventionBuilder jsInitializersEndpoint,
20-
IEndpointConventionBuilder blazorEndpoint)
18+
IEndpointConventionBuilder jsInitializersEndpoint)
2119
{
2220
_hubEndpoint = hubEndpoint;
2321
_disconnectEndpoint = disconnectEndpoint;
2422
_jsInitializersEndpoint = jsInitializersEndpoint;
25-
_blazorEndpoint = blazorEndpoint;
2623
}
2724

2825
/// <summary>
@@ -34,7 +31,6 @@ public void Add(Action<EndpointBuilder> convention)
3431
_hubEndpoint.Add(convention);
3532
_disconnectEndpoint.Add(convention);
3633
_jsInitializersEndpoint.Add(convention);
37-
_blazorEndpoint.Add(convention);
3834
}
3935

4036
/// <inheritdoc/>
@@ -43,6 +39,5 @@ public void Finally(Action<EndpointBuilder> finalConvention)
4339
_hubEndpoint.Finally(finalConvention);
4440
_disconnectEndpoint.Finally(finalConvention);
4541
_jsInitializersEndpoint.Finally(finalConvention);
46-
_blazorEndpoint.Finally(finalConvention);
4742
}
4843
}

src/Components/Server/src/Builder/ComponentEndpointRouteBuilderExtensions.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Components.Server;
5-
using Microsoft.AspNetCore.Http;
65
using Microsoft.AspNetCore.Http.Connections;
76
using Microsoft.AspNetCore.Routing;
87
using Microsoft.AspNetCore.SignalR;
9-
using Microsoft.AspNetCore.StaticFiles;
10-
using Microsoft.Extensions.FileProviders;
118

129
namespace Microsoft.AspNetCore.Builder;
1310

@@ -88,41 +85,6 @@ public static ComponentEndpointConventionBuilder MapBlazorHub(
8885
endpoints.CreateApplicationBuilder().UseMiddleware<CircuitJavaScriptInitializationMiddleware>().Build())
8986
.WithDisplayName("Blazor initializers");
9087

91-
var blazorEndpoint = GetBlazorEndpoint(endpoints);
92-
93-
return new ComponentEndpointConventionBuilder(hubEndpoint, disconnectEndpoint, jsInitializersEndpoint, blazorEndpoint);
94-
}
95-
96-
private static IEndpointConventionBuilder GetBlazorEndpoint(IEndpointRouteBuilder endpoints)
97-
{
98-
var options = new StaticFileOptions
99-
{
100-
FileProvider = new ManifestEmbeddedFileProvider(typeof(ComponentEndpointRouteBuilderExtensions).Assembly),
101-
OnPrepareResponse = CacheHeaderSettings.SetCacheHeaders
102-
};
103-
104-
var app = endpoints.CreateApplicationBuilder();
105-
app.Use(next => context =>
106-
{
107-
// Set endpoint to null so the static files middleware will handle the request.
108-
context.SetEndpoint(null);
109-
110-
return next(context);
111-
});
112-
app.UseStaticFiles(options);
113-
114-
var blazorEndpoint = endpoints.Map("/_framework/blazor.server.js", app.Build())
115-
.WithDisplayName("Blazor static files");
116-
117-
blazorEndpoint.Add((builder) => ((RouteEndpointBuilder)builder).Order = int.MinValue);
118-
119-
#if DEBUG
120-
// We only need to serve the sourcemap when working on the framework, not in the distributed packages
121-
endpoints.Map("/_framework/blazor.server.js.map", app.Build())
122-
.WithDisplayName("Blazor static files sourcemap")
123-
.Add((builder) => ((RouteEndpointBuilder)builder).Order = int.MinValue);
124-
#endif
125-
126-
return blazorEndpoint;
88+
return new ComponentEndpointConventionBuilder(hubEndpoint, disconnectEndpoint, jsInitializersEndpoint);
12789
}
12890
}

0 commit comments

Comments
 (0)