Skip to content

Commit f9f44e1

Browse files
authored
Convert samples to use Aspire (#593)
This updates the samples to use Aspire for connecting the client ASP.NET Core and the server ASP.NET Framework applications. This does the following: - Separate out Directory.Packages.props for samples/src/test. The src one pins all the dependencies so that we know which versions are being used, while the test/samples do not so they can run in a more hybrid setup - Update the folder structure to keep samples together - Update playwright tests to connect via Aspire - Ensure each sample has a smoke test (either via HttpClient or Playwright) - Use libman for managing sample javascript/css files
1 parent da2c5f4 commit f9f44e1

File tree

492 files changed

+1910
-2634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

492 files changed

+1910
-2634
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
Suppress warning for internal experimental APIs
4747
-->
4848
<NoWarn>$(NoWarn);SYSWEB1001</NoWarn>
49+
50+
<!-- We want to run pack on the solution so this allows us to do that -->
51+
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
4952
</PropertyGroup>
5053
</Project>

Microsoft.AspNetCore.SystemWebAdapters.sln

Lines changed: 140 additions & 137 deletions
Large diffs are not rendered by default.

Microsoft.AspNetCore.SystemWebAdapters.slnf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
"test\\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests\\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests.csproj",
1111
"test\\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.Tests\\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.Tests.csproj",
1212
"test\\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests\\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests.csproj",
13-
"test\\Microsoft.AspNetCore.SystemWebAdapters.Tests\\Microsoft.AspNetCore.SystemWebAdapters.Tests.csproj",
14-
"test\\Samples.MVCApp.Tests\\Samples.MVCApp.Tests.csproj",
15-
"test\\Samples.RemoteAuth.Forms.Tests\\Samples.RemoteAuth.Forms.Tests.csproj"
13+
"test\\Microsoft.AspNetCore.SystemWebAdapters.Tests\\Microsoft.AspNetCore.SystemWebAdapters.Tests.csproj"
1614
]
1715
}
18-
}
16+
}

global.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
"dotnet": "10.0.100-preview.5.25265.106",
77
"runtimes": {
88
"dotnet": [
9-
"6.0.4",
10-
"7.0.12",
11-
"8.0.1"
9+
"8.0.16",
10+
"9.0.5"
1211
],
1312
"aspnetcore": [
14-
"6.0.4",
15-
"7.0.12",
16-
"8.0.1"
13+
"8.0.16",
14+
"9.0.5"
1715
]
1816
}
1917
},
2018
"msbuild-sdks": {
21-
"MSBuild.SDK.SystemWeb": "4.0.88",
19+
"MSBuild.SDK.SystemWeb": "4.0.104",
20+
"Aspire.AppHost.Sdk": "9.3.0",
2221
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25279.3"
2322
}
2423
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net9.0-windows</TargetFramework>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<IsAspireHost>true</IsAspireHost>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" />
15+
<PackageReference Include="C3D.Extensions.Aspire.IISExpress" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\AuthRemoteFormsAuthCore\AuthRemoteFormsAuthCore.csproj" />
20+
<ProjectReference Include="..\AuthRemoteFormsAuthFramework\AuthRemoteFormsAuthFramework.csproj" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var remoteApiKey = builder.AddParameter("apiKey", Guid.NewGuid().ToString(), secret: true);
4+
5+
var frameworkApp = builder.AddIISExpress("iis")
6+
.AddSiteProject<Projects.AuthRemoteFormsAuthFramework>("framework")
7+
.WithDefaultIISExpressEndpoints()
8+
.WithEnvironment("RemoteApp__ApiKey", remoteApiKey)
9+
.WithHttpHealthCheck();
10+
11+
var coreApp = builder.AddProject<Projects.AuthRemoteFormsAuthCore>("core")
12+
.WithEnvironment("RemoteApp__ApiKey", remoteApiKey)
13+
.WithEnvironment("RemoteApp__Url", frameworkApp.GetEndpoint("https"))
14+
.WithHttpHealthCheck()
15+
.WaitFor(frameworkApp);
16+
17+
builder.Build().Run();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17095;http://localhost:15283",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21002",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22119"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15283",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19075",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035"
26+
}
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Yarp.ReverseProxy" />
99
</ItemGroup>
1010
<ItemGroup>
11-
<ProjectReference Include="..\..\..\..\src\Microsoft.AspNetCore.SystemWebAdapters.CoreServices\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.csproj" />
11+
<ProjectReference Include="..\..\ServiceDefaults\Samples.ServiceDefaults.Core\Samples.ServiceDefaults.Core.csproj" />
1212
</ItemGroup>
1313
</Project>

samples/RemoteAuth/Forms/FormsAuthCore/Program.cs renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/Program.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var builder = WebApplication.CreateBuilder(args);
22

3-
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
3+
builder.AddServiceDefaults();
4+
5+
builder.Services.AddReverseProxy();
46

57
// Add services to the container.
68
builder.Services.AddControllersWithViews();
@@ -9,8 +11,8 @@
911
builder.Services.AddSystemWebAdapters()
1012
.AddRemoteAppClient(options =>
1113
{
12-
options.RemoteAppUrl = new(builder.Configuration["ProxyTo"]!);
13-
options.ApiKey = builder.Configuration["RemoteAppApiKey"]!;
14+
options.RemoteAppUrl = new(builder.Configuration["RemoteApp:Url"]!);
15+
options.ApiKey = builder.Configuration["RemoteApp:ApiKey"]!;
1416
})
1517
.AddAuthenticationClient(true);
1618

@@ -37,6 +39,14 @@
3739
app.MapControllerRoute(
3840
name: "default",
3941
pattern: "{controller=Home}/{action=Index}/{id?}");
40-
app.MapForwarder("/{**catch-all}", app.Configuration["ProxyTo"]!).WithOrder(int.MaxValue);
42+
43+
// Configure the reverse proxy to forward all unhandled requests to the remote app
44+
app.MapForwarder("/{**catch-all}", app.Configuration["RemoteApp:Url"]!)
45+
46+
// If there is a route locally, we want to ensure that is used by default, but otherwise we'll forward
47+
.WithOrder(int.MaxValue)
48+
49+
// If we're going to forward the request, there is no need to run any of the middleware after routing
50+
.ShortCircuit();
4151

4252
app.Run();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"profiles": {
3+
"FormsAuthCore": {
4+
"commandName": "Project",
5+
"dotnetRunMessages": true,
6+
"launchBrowser": true,
7+
"applicationUrl": "https://localhost:7080;http://localhost:5080",
8+
"environmentVariables": {
9+
"ASPNETCORE_ENVIRONMENT": "Development"
10+
}
11+
}
12+
}
13+
}

samples/RemoteSession/RemoteSessionCore/appsettings.json renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthCore/appsettings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
},
88
"AllowedHosts": "*",
99
"RemoteApp": {
10-
"Key": "23EB1AEF-E019-4850-A257-3DB3A85495BD",
11-
"Url": "https://localhost:44305"
10+
"ApiKey": "** PROVIDE UNIQUE KEY **",
11+
"Url": "** URL to remote app **"
1212
}
13-
1413
}

samples/RemoteAuth/Forms/FormsAuth/App_Start/BundleConfig.cs renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/App_Start/BundleConfig.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Web;
@@ -29,10 +29,20 @@ public static void RegisterBundles(BundleCollection bundles)
2929
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
3030
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));
3131

32-
// Use the Development version of Modernizr to develop with and learn from. Then, when you’re
33-
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need
34-
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
35-
"~/Scripts/modernizr-*"));
32+
bundles.Add(new ScriptBundle("~/bundles/jquery.js").Include(
33+
"~/Scripts/jquery/dist/jquery.min.js"));
34+
35+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
36+
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
37+
bundles.Add(new ScriptBundle("~/bundles/modernizr.js").Include(
38+
"~/Scripts/modernizr/src/Modernizr.min.js"));
39+
40+
bundles.Add(new ScriptBundle("~/bundles/bootstrap.js").Include(
41+
"~/Scripts/bootstrap/dist/js/bootstrap.min.js"));
42+
43+
bundles.Add(new StyleBundle("~/Content/css").Include(
44+
"~/Scripts/bootstrap/dist/css/bootstrap.min.css",
45+
"~/Content/site.css"));
3646
}
3747
}
38-
}
48+
}

samples/RemoteAuth/Forms/FormsAuth/FormsAuth.csproj renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Antlr" />
7-
<PackageReference Include="AspNet.ScriptManager.bootstrap" />
8-
<PackageReference Include="AspNet.ScriptManager.jQuery.UI.Combined" />
9-
<PackageReference Include="AspNet.ScriptManager.jQuery" />
10-
<PackageReference Include="bootstrap" GeneratePathProperty="true" CopyContent="true" />
11-
<PackageReference Include="jQuery" CopyContent="true" />
127
<PackageReference Include="Microsoft.AspNet.FriendlyUrls" />
138
<PackageReference Include="Microsoft.AspNet.ScriptManager.MSAjax" GeneratePathProperty="true" CopyContent="true" />
149
<PackageReference Include="Microsoft.AspNet.ScriptManager.WebForms" GeneratePathProperty="true" CopyContent="true" />
1510
<PackageReference Include="Microsoft.AspNet.Web.Optimization.WebForms" NoWarn="NU1602" />
16-
<PackageReference Include="Modernizr" CopyContent="true" />
11+
<PackageReference Include="Microsoft.Configuration.ConfigurationBuilders.Environment" />
1712
<PackageReference Include="Newtonsoft.Json" />
1813
<PackageReference Include="WebGrease" />
1914
<PackageReference Include="Microsoft.Web.Infrastructure" />
2015
</ItemGroup>
2116
<ItemGroup>
22-
<ProjectReference Include="..\..\..\..\src\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.csproj" />
23-
<ProjectReference Include="..\..\..\FrameworkSampleUtilities\FrameworkSampleUtilities.csproj" />
17+
<ProjectReference Include="..\..\ServiceDefaults\Samples.ServiceDefaults.Framework\Samples.ServiceDefaults.Framework.csproj" />
2418
</ItemGroup>
2519
<ItemGroup>
2620
<Reference Include="System.Configuration" />

samples/RemoteAuth/Forms/FormsAuth/Global.asax.cs renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Global.asax.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void Application_Start(object sender, EventArgs e)
1616
.AddProxySupport(options => options.UseForwardedHeaders = true)
1717
.AddRemoteAppServer(options =>
1818
{
19-
options.ApiKey = ConfigurationManager.AppSettings["RemoteAppApiKey"];
19+
options.ApiKey = ConfigurationManager.AppSettings["RemoteApp__ApiKey"];
2020
})
2121
.AddAuthenticationServer();
2222

samples/RemoteAuth/Forms/FormsAuth/Properties/launchSettings.json renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"profiles": {
1010
"IIS Express": {
1111
"commandName": "IISExpress",
12-
"launchBrowser": false
12+
"launchBrowser": true
1313
}
1414
}
1515
}

samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Scripts/bootstrap/dist/css/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Scripts/bootstrap/dist/js/bootstrap.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Scripts/jquery/dist/jquery.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Scripts/modernizr/src/Modernizr.min.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/RemoteAuth/Forms/FormsAuth/Site.Master renamed to samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/Site.Master

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="FormsAuth.SiteMaster" %>
1+
<%@ master language="C#" autoeventwireup="true" codebehind="Site.master.cs" inherits="FormsAuth.SiteMaster" %>
22

33
<!DOCTYPE html>
44

@@ -19,12 +19,12 @@
1919
<body>
2020
<form runat="server">
2121
<asp:ScriptManager runat="server">
22-
<Scripts>
22+
<scripts>
2323
<%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
2424
<%--Framework Scripts--%>
2525
<asp:ScriptReference Name="MsAjaxBundle" />
26-
<asp:ScriptReference Name="jquery" />
27-
<asp:ScriptReference Name="bootstrap" />
26+
<asp:ScriptReference Path="~/bundles/jquery.js" />
27+
<asp:ScriptReference Path="~/bundles/bootstrap.js" />
2828
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
2929
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
3030
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
@@ -35,41 +35,39 @@
3535
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
3636
<asp:ScriptReference Name="WebFormsBundle" />
3737
<%--Site Scripts--%>
38-
</Scripts>
38+
</scripts>
3939
</asp:ScriptManager>
4040

41-
<div class="navbar navbar-inverse navbar-fixed-top">
42-
<div class="container">
43-
<div class="navbar-header">
44-
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" title="more options">
45-
<span class="icon-bar"></span>
46-
<span class="icon-bar"></span>
47-
<span class="icon-bar"></span>
48-
</button>
49-
<a class="navbar-brand" runat="server" href="~/">Application name</a>
50-
</div>
51-
<div class="navbar-collapse collapse">
52-
<ul class="nav navbar-nav">
53-
<li><a runat="server" href="~/">Home</a></li>
54-
<li><a runat="server" href="~/About">About</a></li>
55-
<li><a runat="server" href="~/Contact">Contact</a></li>
41+
<header>
42+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
43+
<a class="navbar-brand" runat="server" href="~/">Application name</a>
44+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" title="more options">
45+
<span class="navbar-toggler-icon"></span>
46+
</button>
47+
48+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
49+
<ul class="nav navbar-nav flex-grow-1">
50+
<li><a class="nav-link" runat="server" href="~/">Home</a></li>
51+
<li><a class="nav-link" runat="server" href="~/About">About</a></li>
52+
<li><a class="nav-link" runat="server" href="~/Contact">Contact</a></li>
5653
</ul>
57-
<div class="nav navbar-nav navbar-right navbar-brand">
54+
<div class="nav navbar-nav navbar-right">
5855
<asp:LoginView ID="LoginView1" runat="server">
59-
<LoggedInTemplate>
56+
<loggedintemplate>
6057
Welcome back,
61-
<asp:LoginName ID="LoginName1" runat="server" />.
62-
</LoggedInTemplate>
63-
<AnonymousTemplate>
58+
<asp:LoginName ID="LoginName1" runat="server" />
59+
.
60+
</loggedintemplate>
61+
<anonymoustemplate>
6462
Welcome, anonymous user
65-
</AnonymousTemplate>
63+
</anonymoustemplate>
6664
</asp:LoginView>
6765
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" />
6866
</div>
6967
</div>
70-
</div>
71-
</div>
72-
<div class="container body-content" style="margin-top:50px">
68+
</nav>
69+
</header>
70+
<div class="container body-content" style="margin-top: 50px">
7371
<asp:ContentPlaceHolder ID="MainContent" runat="server">
7472
</asp:ContentPlaceHolder>
7573
<hr />

0 commit comments

Comments
 (0)