Skip to content
Merged
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
2 changes: 2 additions & 0 deletions eng/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ may be turned into `<PackageReference>` items in projects.
<LatestPackageReference Include="xunit.v3.extensibility.core" Version="$(XunitV3ExtensibilityCoreVersion)" />
<LatestPackageReference Include="Microsoft.Playwright.Xunit.v3" Version="$(MicrosoftPlaywrightXunitV3Version)" />
<LatestPackageReference Include="Yarp.ReverseProxy" Version="$(YarpReverseProxyVersion)" />
<LatestPackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<LatestPackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" />
</ItemGroup>

<ItemGroup Label="Dependencies with versions.">
Expand Down
4 changes: 4 additions & 0 deletions eng/Version.Details.props
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ This file should be imported by eng/Versions.props
<!-- dotnet-extensions dependencies -->
<MicrosoftExtensionsCachingHybridPackageVersion>10.6.0-preview.1.26210.2</MicrosoftExtensionsCachingHybridPackageVersion>
<MicrosoftExtensionsDiagnosticsTestingPackageVersion>10.6.0-preview.1.26210.2</MicrosoftExtensionsDiagnosticsTestingPackageVersion>
<MicrosoftExtensionsServiceDiscoveryPackageVersion>10.6.0-preview.1.26210.2</MicrosoftExtensionsServiceDiscoveryPackageVersion>
<MicrosoftExtensionsServiceDiscoveryYarpPackageVersion>10.6.0-preview.1.26210.2</MicrosoftExtensionsServiceDiscoveryYarpPackageVersion>
<MicrosoftExtensionsTimeProviderTestingPackageVersion>10.6.0-preview.1.26210.2</MicrosoftExtensionsTimeProviderTestingPackageVersion>
<!-- dotnet-msbuild dependencies -->
<MicrosoftBuildPackageVersion>17.12.50</MicrosoftBuildPackageVersion>
Expand Down Expand Up @@ -218,6 +220,8 @@ This file should be imported by eng/Versions.props
<MicrosoftExtensionsCachingHybridVersion>$(MicrosoftExtensionsCachingHybridPackageVersion)</MicrosoftExtensionsCachingHybridVersion>
<MicrosoftExtensionsDiagnosticsTestingVersion>$(MicrosoftExtensionsDiagnosticsTestingPackageVersion)</MicrosoftExtensionsDiagnosticsTestingVersion>
<MicrosoftExtensionsTimeProviderTestingVersion>$(MicrosoftExtensionsTimeProviderTestingPackageVersion)</MicrosoftExtensionsTimeProviderTestingVersion>
<MicrosoftExtensionsServiceDiscoveryVersion>$(MicrosoftExtensionsServiceDiscoveryPackageVersion)</MicrosoftExtensionsServiceDiscoveryVersion>
<MicrosoftExtensionsServiceDiscoveryYarpVersion>$(MicrosoftExtensionsServiceDiscoveryYarpPackageVersion)</MicrosoftExtensionsServiceDiscoveryYarpVersion>
<!-- dotnet-msbuild dependencies -->
<MicrosoftBuildVersion>$(MicrosoftBuildPackageVersion)</MicrosoftBuildVersion>
<MicrosoftBuildFrameworkVersion>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildFrameworkVersion>
Expand Down
8 changes: 8 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@
<Uri>https://github.com/dotnet/extensions</Uri>
<Sha>03a9943b2a2ebbc8e2cd9336ba1defcdaf6ffefd</Sha>
</Dependency>
<Dependency Name="Microsoft.Extensions.ServiceDiscovery" Version="10.4.1">
<Uri>https://github.com/dotnet/extensions</Uri>
<Sha>24c7e4fc4f08e94d9e977bac3ab7b352762e28b2</Sha>
</Dependency>
<Dependency Name="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="10.4.1">
<Uri>https://github.com/dotnet/extensions</Uri>
<Sha>24c7e4fc4f08e94d9e977bac3ab7b352762e28b2</Sha>
</Dependency>
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.26180.1">
<Uri>https://dev.azure.com/dnceng/internal/_git/dotnet-optimization</Uri>
<Sha>9f55ee44f6d99b78f3e80f77e2ed73fb73b8f63b</Sha>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
<MessagePackVersion>2.5.187</MessagePackVersion>
<!-- Extensions packages for Blazor WASM Service Defaults -->
<MicrosoftExtensionsHttpResilienceVersion>10.0.0</MicrosoftExtensionsHttpResilienceVersion>
<MicrosoftExtensionsServiceDiscoveryVersion>10.0.0</MicrosoftExtensionsServiceDiscoveryVersion>
<MicrosoftIdentityWebVersion>3.14.1</MicrosoftIdentityWebVersion>
<MicrosoftIdentityWebGraphServiceClientVersion>3.14.1</MicrosoftIdentityWebGraphServiceClientVersion>
<MicrosoftIdentityWebUIVersion>3.14.1</MicrosoftIdentityWebUIVersion>
Expand Down Expand Up @@ -195,6 +194,7 @@
<MicrosoftPlaywrightXunitV3Version>1.58.0</MicrosoftPlaywrightXunitV3Version>
<!-- Components.Testing dependencies -->
<YarpReverseProxyVersion>2.3.0</YarpReverseProxyVersion>
<MicrosoftExtensionsServiceDiscoveryYarpVersion>$(MicrosoftExtensionsServiceDiscoveryVersion)</MicrosoftExtensionsServiceDiscoveryYarpVersion>
<MicrosoftDataSqlClientVersion>7.0.0</MicrosoftDataSqlClientVersion>
<MicrosoftDataSqlClientExtensionsAzureVersion>1.0.0</MicrosoftDataSqlClientExtensionsAzureVersion>
<MicrosoftOpenApiVersion>3.3.1</MicrosoftOpenApiVersion>
Expand Down
76 changes: 76 additions & 0 deletions src/Components/Gateway/src/BlazorGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components.Gateway;

/// <summary>
/// Intended for framework test use only.
/// </summary>
public static class BlazorGateway
{
Comment thread
javiercn marked this conversation as resolved.
Resolved
/// <summary>
/// Builds a <see cref="WebApplication"/> configured as a Blazor Gateway.
/// Reads ClientApps config section for endpoint manifests and YARP reverse proxy configuration.
/// </summary>
public static WebApplication BuildWebHost(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseStaticWebAssets();

var appConfigs = builder.Configuration.GetSection("ClientApps")
.Get<Dictionary<string, ClientAppConfiguration>>() ?? [];

var proxySection = builder.Configuration.GetSection("ReverseProxy");
var hasProxy = proxySection.Exists();

if (hasProxy)
{
builder.Services.AddReverseProxy()
.LoadFromConfig(proxySection)
.AddServiceDiscoveryDestinationResolver();
}

var app = builder.Build();

var pathBase = builder.Configuration.GetValue<string>("pathbase");
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}

if (hasProxy)
{
app.MapReverseProxy();
}

foreach (var appConfig in appConfigs.Values)
{
if (!string.IsNullOrEmpty(appConfig.ConfigEndpointPath) && !string.IsNullOrEmpty(appConfig.ConfigResponse))
{
app.MapGet(appConfig.ConfigEndpointPath, () => Results.Content(appConfig.ConfigResponse, "application/json"))
.WithMetadata(new ContentEncodingMetadata("identity", 1.0));
}

if (!string.IsNullOrEmpty(appConfig.EndpointsManifest))
{
app.MapGroup(appConfig.PathPrefix ?? "").MapStaticAssets(appConfig.EndpointsManifest);
}
}

// SPA fallback: serve index.html for any non-file URL path, similar to
// the old DevServer's MapFallbackToFile("index.html"). This is registered
// after MapStaticAssets so that specific static file routes take precedence.
app.MapFallbackToFile("index.html");
Comment on lines +61 to +64

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is until we get fallbacks on the SDK


return app;
}
}

sealed class ClientAppConfiguration
{
public string? PathPrefix { get; set; }
public string? EndpointsManifest { get; set; }
public string? ConfigEndpointPath { get; set; }
public string? ConfigResponse { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<AssemblyName>blazor-gateway</AssemblyName>
<PackageId>Microsoft.AspNetCore.Components.Gateway</PackageId>
<IsShippingPackage>true</IsShippingPackage>
<Description>Gateway server for hosting standalone Blazor WebAssembly applications.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Assemblies should not reference this assembly directly -->
<IsProjectReferenceProvider>false</IsProjectReferenceProvider>
<AddPublicApiAnalyzers>false</AddPublicApiAnalyzers>
<Nullable>enable</Nullable>
<!-- Disable the default runtimeconfig.json in favor of the one we create via template,
which contains the correct framework version. -->
<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
<!-- Allow direct PackageReference for external packages not in the shared framework -->
<DisablePackageReferenceRestrictions>true</DisablePackageReferenceRestrictions>
<!-- Use the shared ASP.NET Core runtime from the SDK targeting pack instead of requiring
the local shared framework build (Microsoft.AspNetCore.App.Runtime.sfxproj).
UseAspNetCoreSharedRuntime prevents removal of the KnownFrameworkReference.
DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp prevents the version override to 10.0.0-dev. -->
<UseAspNetCoreSharedRuntime>true</UseAspNetCoreSharedRuntime>
<DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp>true</DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp>
</PropertyGroup>

<ItemGroup>
<Reference Include="Yarp.ReverseProxy" />
<Reference Include="Microsoft.Extensions.ServiceDiscovery" />
<Reference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" />
</ItemGroup>

<Target Name="_CreateRuntimeConfig" BeforeTargets="CoreBuild">
<PropertyGroup>
<_RuntimeConfigProperties Condition="'$(IsServicingBuild)' == 'true'">
FrameworkVersion=$(AspNetCoreMajorMinorVersion).0;
</_RuntimeConfigProperties>
<_RuntimeConfigProperties Condition="'$(IsServicingBuild)' != 'true'">
FrameworkVersion=$(SharedFxVersion);
</_RuntimeConfigProperties>

<_RuntimeConfigPath>$(OutputPath)blazor-gateway.runtimeconfig.json</_RuntimeConfigPath>
</PropertyGroup>

<GenerateFileFromTemplate
TemplateFile="blazor-gateway.runtimeconfig.json.in"
Properties="$(_RuntimeConfigProperties)"
OutputPath="$(_RuntimeConfigPath)" />
</Target>

<!-- Pack settings -->
<PropertyGroup>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);publish</GenerateNuspecDependsOn>
<NoPackageAnalysis>true</NoPackageAnalysis>
<NuspecFile>Microsoft.AspNetCore.Components.Gateway.nuspec</NuspecFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.Build.Tasks.Templating" PrivateAssets="All" Version="$(MicrosoftDotNetBuildTasksTemplatingVersion)" IsImplicitlyDefined="true" AllowExplicitReference="true" />
</ItemGroup>

<ItemGroup>
<NuspecProperty Include="publishDir=$(PublishDir)" />
<NuspecProperty Include="binDir=$(OutputPath)" />
<NuspecProperty Include="PackageThirdPartyNoticesFile=$(PackageThirdPartyNoticesFile)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
$CommonMetadataElements$
</metadata>
<files>
$CommonFileElements$
<file src="build\**" target="build" />
<file src="$publishDir$**\*" target="tools" />
<file src="$PackageThirdPartyNoticesFile$" target=".\THIRD-PARTY-NOTICES.txt" />
<file src="$binDir$blazor-gateway.runtimeconfig.json" target="tools\blazor-gateway.runtimeconfig.json" />
</files>
</package>
6 changes: 6 additions & 0 deletions src/Components/Gateway/src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.Gateway;

BlazorGateway.BuildWebHost(args).Run();
10 changes: 10 additions & 0 deletions src/Components/Gateway/src/blazor-gateway.runtimeconfig.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
Comment thread
javiercn marked this conversation as resolved.
Resolved
"runtimeOptions": {
"tfm": "net11.0",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "${FrameworkVersion}"
},
"rollForwardOnNoCandidateFx": 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<_BlazorGatewayDll Condition="'$(_BlazorGatewayDll)' == ''">$(MSBuildThisFileDirectory)../tools/blazor-gateway.dll</_BlazorGatewayDll>
<!-- Prevents the runtime SDK (Microsoft.NET.Sdk.WebAssembly.Browser.targets) from overriding
RunCommand/RunArguments with WasmAppHost when _UseBlazorDevServer is false. -->
<_WebAssemblyUserRunParameters>true</_WebAssemblyUserRunParameters>
Comment thread
javiercn marked this conversation as resolved.
Resolved
</PropertyGroup>

<Target Name="_BlazorGatewayComputeRunArguments" AfterTargets="ComputeRunArguments" DependsOnTargets="ResolveStaticWebAssetsConfiguration">
Comment thread
javiercn marked this conversation as resolved.
Resolved
<PropertyGroup>
<RunCommand>dotnet</RunCommand>
<_GatewayStaticWebAssetsManifest>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(StaticWebAssetDevelopmentManifestPath)'))</_GatewayStaticWebAssetsManifest>
<_GatewayEndpointsManifest>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(StaticWebAssetEndpointsBuildManifestPath)'))</_GatewayEndpointsManifest>
<RunArguments>&quot;$(_BlazorGatewayDll)&quot; --environment Development --staticWebAssets &quot;$(_GatewayStaticWebAssetsManifest)&quot; --ClientApps:app:EndpointsManifest &quot;$(_GatewayEndpointsManifest)&quot; --ClientApps:app:PathPrefix &quot;&quot;</RunArguments>
Comment thread
javiercn marked this conversation as resolved.
Resolved
</PropertyGroup>
</Target>
</Project>
27 changes: 27 additions & 0 deletions src/Components/WebAssembly/testassets/SpaFallback.targets

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary until the SDK update flows to asp.net core

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Temporary targets file that adds a SPA fallback endpoint to the static web assets
endpoints manifest. This will be removed once the SDK ships StaticWebAssetSpaFallbackEnabled.
-->
<Project>
<PropertyGroup>
<GenerateStaticWebAssetsManifestDependsOn>$(GenerateStaticWebAssetsManifestDependsOn);_AddSpaFallbackEndpoint</GenerateStaticWebAssetsManifestDependsOn>
</PropertyGroup>

<Target Name="_AddSpaFallbackEndpoint">
<ItemGroup>
<!-- Find the identity (uncompressed) index.html endpoint: Route == index.html, AssetFile not .gz/.br -->
<_SpaFallbackCandidate Include="@(StaticWebAssetEndpoint)"
Condition="'%(Identity)' == 'index.html' and !$([System.String]::Copy('%(AssetFile)').EndsWith('.gz')) and !$([System.String]::Copy('%(AssetFile)').EndsWith('.br'))" />
</ItemGroup>

<ItemGroup Condition="'@(_SpaFallbackCandidate)' != ''">
<!-- Add a clone with route changed to the SPA catch-all pattern -->
<StaticWebAssetEndpoint Include="{**path:nonfile}"
AssetFile="%(_SpaFallbackCandidate.AssetFile)"
Selectors="%(_SpaFallbackCandidate.Selectors)"
EndpointProperties="%(_SpaFallbackCandidate.EndpointProperties)"
ResponseHeaders="%(_SpaFallbackCandidate.ResponseHeaders)"
Order="$([System.Int32]::MaxValue)" />
</ItemGroup>
</Target>
Comment thread
javiercn marked this conversation as resolved.
Resolved
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<!-- Point to the locally-built Gateway DLL -->
<_BlazorGatewayDll>$(RepoRoot)artifacts\bin\Microsoft.AspNetCore.Components.Gateway\$(Configuration)\$(DefaultNetCoreTargetFramework)\blazor-gateway.dll</_BlazorGatewayDll>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
</ItemGroup>

<Import Project="$(RepoRoot)src\Components\Gateway\src\build\Microsoft.AspNetCore.Components.Gateway.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\SpaFallback.targets" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\SpaFallback.targets" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
</ItemGroup>

<Import Project="$(RepoRoot)src\Components\WebAssembly\testassets\SpaFallback.targets" />

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Gateway;
using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TestServer;
using DevHostServerProgram = Microsoft.AspNetCore.Components.WebAssembly.DevServer.Server.Program;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;

Expand Down Expand Up @@ -49,12 +49,15 @@ protected override IHost CreateWebHost()
host = E2ETestOptions.Instance.Sauce.HostName;
}

var assemblyLocation = typeof(TProgram).Assembly.Location;
var args = new List<string>
{
"--urls", $"http://{host}:0",
"--contentroot", ContentRoot,
"--pathbase", PathBase,
"--applicationpath", typeof(TProgram).Assembly.Location,
"--staticWebAssets", Path.ChangeExtension(assemblyLocation, ".staticwebassets.runtime.json"),
"--ClientApps:app:EndpointsManifest", Path.ChangeExtension(assemblyLocation, ".staticwebassets.endpoints.json"),
"--ClientApps:app:PathPrefix", "",
};

if (!string.IsNullOrEmpty(Environment))
Expand All @@ -68,7 +71,7 @@ protected override IHost CreateWebHost()
args.Add("--apply-cop-headers");
}

return DevHostServerProgram.BuildWebHost(args.ToArray());
return BlazorGateway.BuildWebHost(args.ToArray());
}

private IHost CreateStaticWebHost(string contentRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,26 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\..\WebAssembly\DevServer\src\Server\*.cs" />
<Compile Include="..\..\..\Gateway\src\BlazorGateway.cs" />
</ItemGroup>

<ItemGroup>
<Reference Include="Yarp.ReverseProxy" />
<Reference Include="Microsoft.Extensions.ServiceDiscovery" />
<Reference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" />
</ItemGroup>

<!-- YARP NuGet packages transitively add a FrameworkReference to Microsoft.AspNetCore.App
via AddTransitiveFrameworkReferences (after ResolvePackageAssets). TestServer gets the
framework via project references, so remove it before targeting pack resolution. -->
<Target Name="_RemoveTransitiveAspNetCoreFrameworkReference"
AfterTargets="AddTransitiveFrameworkReferences"
BeforeTargets="ResolveTargetingPackAssets">
<ItemGroup>
<FrameworkReference Remove="Microsoft.AspNetCore.App" />
</ItemGroup>
</Target>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Microsoft.AspNetCore.InternalTesting.BasicTestApp.ContentRoot</_Parameter1>
Expand Down
Loading
Loading