Skip to content

Commit adc5a36

Browse files
authored
Add support for EnableRequestDelegateGenerator flag (#29982)
1 parent ea03dc7 commit adc5a36

22 files changed

+90
-23
lines changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tools": {
3-
"dotnet": "8.0.100-alpha.1.23061.8",
3+
"dotnet": "8.0.100-alpha.1.23067.5",
44
"runtimes": {
55
"dotnet": [
66
"$(VSRedistCommonNetCoreSharedFrameworkx6480PackageVersion)"

src/BuiltInTools/BrowserRefresh/BlazorWasmHotReloadMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ private void WriteETag(HttpContext context)
111111
return string.Format(CultureInfo.InvariantCulture, "W/\"{0}{1}\"", EtagDiscriminator, Deltas[^1].SequenceId);
112112
}
113113

114-
private void AppendDeltas(UpdateDelta[] updateDeltas)
114+
private void AppendDeltas(UpdateDelta[]? updateDeltas)
115115
{
116-
if (updateDeltas.Length == 0)
116+
if (updateDeltas == null || updateDeltas.Length == 0)
117117
{
118118
return;
119119
}

src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<!-- Intentionally pinned. This feature is supported in projects targeting 3.1 or newer.-->
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<!-- Intentionally pinned. This feature is supported in projects targeting 6.0 or newer.-->
4+
<TargetFramework>net6.0</TargetFramework>
55
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
66

77
<IsPackable>false</IsPackable>

src/Layout/toolset-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Build.Tasks
2121
/// and then update the stage 0 back.
2222
///
2323
/// Override NETCoreSdkVersion to stage 0 sdk version like 6.0.100-dev
24-
///
24+
///
2525
/// Use a task to override since it was generated as a string literal replace anyway.
2626
/// And using C# can have better error when anything goes wrong.
2727
/// </summary>

src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/Microsoft.NET.Sdk.WorkloadManifestReader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>$(ResolverTargetFramework);net472;netcoreapp3.1</TargetFrameworks>
4+
<TargetFrameworks>$(ResolverTargetFramework);net472</TargetFrameworks>
55
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">$(ResolverTargetFramework)</TargetFrameworks>
66

77
<PlatformTarget>AnyCPU</PlatformTarget>

src/Tests/HelixTasks/HelixTasks.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
4-
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">netcoreapp3.1</TargetFrameworks>
3+
<TargetFrameworks>net6.0;net472</TargetFrameworks>
4+
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">net6.0</TargetFrameworks>
55
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
66
<RootNamespace>Microsoft.DotNet.SDK.Build.Helix</RootNamespace>
77
</PropertyGroup>

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@ public GivenThatWeWantToUseAnalyzers(ITestOutputHelper log) : base(log)
2323
{
2424
}
2525

26+
[Theory]
27+
[InlineData("WebApp", false)]
28+
[InlineData("WebApp", true)]
29+
[InlineData("WebApp", null)]
30+
public void It_resolves_requestdelegategenerator_correctly(string testAssetName, bool? isEnabled)
31+
{
32+
var asset = _testAssetsManager
33+
.CopyTestAsset(testAssetName, identifier: isEnabled.ToString())
34+
.WithSource()
35+
.WithProjectChanges(project =>
36+
{
37+
if (isEnabled != null)
38+
{
39+
var ns = project.Root.Name.Namespace;
40+
project.Root.Add(new XElement(ns + "PropertyGroup", new XElement("EnableRequestDelegateGenerator", isEnabled)));
41+
}
42+
});
43+
44+
var command = new GetValuesCommand(
45+
Log,
46+
asset.Path,
47+
ToolsetInfo.CurrentTargetFramework,
48+
"Analyzer",
49+
GetValuesCommand.ValueType.Item);
50+
51+
command
52+
.WithWorkingDirectory(asset.Path)
53+
.Execute()
54+
.Should().Pass();
55+
56+
var analyzers = command.GetValues();
57+
58+
Assert.Equal(isEnabled ?? false, analyzers.Any(analyzer => analyzer.Contains("Microsoft.AspNetCore.Http.Generators.dll")));
59+
}
60+
2661
[Theory]
2762
[InlineData("C#", "AppWithLibrary")]
2863
[InlineData("VB", "AppWithLibraryVB")]

src/Tests/dotnet-new.Tests/Approvals/DotnetNewCompleteTests.CanDoTabCompletion.Linux.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
angular
2+
api
23
blazorserver
34
blazorserver-empty
45
blazorwasm

src/Tests/dotnet-new.Tests/Approvals/DotnetNewCompleteTests.CanDoTabCompletion.OSX.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
angular
2+
api
23
blazorserver
34
blazorserver-empty
45
blazorwasm

src/Tests/dotnet-new.Tests/Approvals/DotnetNewCompleteTests.CanDoTabCompletion.Windows.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
angular
2+
api
23
blazorserver
34
blazorserver-empty
45
blazorwasm

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenLegacyCommandIsUsed_common.Linux.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ These templates matched your input:
66

77
Template Name Short Name Language Tags
88
-------------------------------------------- -------------------------- ---------- --------------------------------
9+
ASP.NET Core API api [C#] Web/API
910
ASP.NET Core Empty web [C#],F# Web/Empty
1011
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
1112
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenLegacyCommandIsUsed_common.OSX.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ These templates matched your input:
66

77
Template Name Short Name Language Tags
88
-------------------------------------------- -------------------------- ---------- --------------------------------
9+
ASP.NET Core API api [C#] Web/API
910
ASP.NET Core Empty web [C#],F# Web/Empty
1011
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
1112
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenLegacyCommandIsUsed_common.Windows.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ These templates matched your input:
66

77
Template Name Short Name Language Tags
88
-------------------------------------------- -------------------------- ---------- --------------------------------
9+
ASP.NET Core API api [C#] Web/API
910
ASP.NET Core Empty web [C#],F# Web/Empty
1011
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
1112
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenListCommandIsUsed.Linux.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Template Name Short Name Language Tags
44
-------------------------------------------- -------------------------- ---------- --------------------------------
5+
ASP.NET Core API api [C#] Web/API
56
ASP.NET Core Empty web [C#],F# Web/Empty
67
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
78
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenListCommandIsUsed.OSX.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Template Name Short Name Language Tags
44
-------------------------------------------- -------------------------- ---------- --------------------------------
5+
ASP.NET Core API api [C#] Web/API
56
ASP.NET Core Empty web [C#],F# Web/Empty
67
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
78
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/DotnetNewListTests.BasicTest_WhenListCommandIsUsed.Windows.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Template Name Short Name Language Tags
44
-------------------------------------------- -------------------------- ---------- --------------------------------
5+
ASP.NET Core API api [C#] Web/API
56
ASP.NET Core Empty web [C#],F# Web/Empty
67
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
78
ASP.NET Core Web API webapi [C#],F# Web/WebAPI

src/Tests/dotnet-new.Tests/Approvals/WebProjectsTests.CanShowHelp_Mvc.verified.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Template options:
3232
-ssp, --susi-policy-id <susi-policy-id> The sign-in and sign-up policy ID for this project (use with IndividualB2C auth).
3333
Type: string
3434
Default: b2c_1_susi
35-
-S, --SignedOutCallbackPath <SignedOutCallbackPath> The global signout callback (use with IndividualB2C auth).
35+
-socp, --signed-out-callback-path <signed-out-callback-path> The global signout callback (use with IndividualB2C auth).
3636
Type: string
3737
Default: /signout/B2C_1_susi
3838
-rp, --reset-password-policy-id <reset-password-policy-id> The reset password policy ID for this project (use with IndividualB2C auth).
@@ -68,11 +68,12 @@ Template options:
6868
-uld, --use-local-db Whether to use LocalDB instead of SQLite. This option only applies if --auth Individual or --auth IndividualB2C is specified.
6969
Type: bool
7070
Default: false
71-
-f, --framework <net6.0|net7.0> The target framework for the project.
71+
-f, --framework <net6.0|net7.0|net8.0> The target framework for the project.
7272
Type: choice
73+
net8.0 Target net8.0
7374
net7.0 Target net7.0
7475
net6.0 Target net6.0
75-
Default: net7.0
76+
Default: net8.0
7677
--no-restore If specified, skips the automatic restore of the project on create.
7778
Type: bool
7879
Default: false
@@ -88,6 +89,9 @@ Template options:
8889
--use-program-main Whether to generate an explicit Program class and Main method instead of top-level statements.
8990
Type: bool
9091
Default: false
92+
-S, --SignedOutCallbackPath <SignedOutCallbackPath> The global signout callback (use with IndividualB2C auth).
93+
Type: string
94+
Default: /signout/B2C_1_susi
9195

9296
To see help for other template languages (F#), use --language option:
9397
dotnet new mvc -h --language F#

src/Tests/dotnet-new.Tests/Approvals/WebProjectsTests.CanShowHelp_WebAPI.verified.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ Template options:
5959
-minimal, --use-minimal-apis Whether to use minimal APIs instead of controllers.
6060
Type: bool
6161
Default: false
62-
-f, --framework <net6.0|net7.0> The target framework for the project.
62+
-f, --framework <net6.0|net7.0|net8.0> The target framework for the project.
6363
Type: choice
64+
net8.0 Target net8.0
6465
net7.0 Target net7.0
6566
net6.0 Target net6.0
66-
Default: net7.0
67+
Default: net8.0
6768
--no-restore If specified, skips the automatic restore of the project on create.
6869
Type: bool
6970
Default: false

src/Tests/dotnet-new.Tests/Approvals/WebProjectsTests.CanShowHelp_Webapp_common.verified.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Template options:
3333
-ssp, --susi-policy-id <susi-policy-id> The sign-in and sign-up policy ID for this project (use with IndividualB2C auth).
3434
Type: string
3535
Default: b2c_1_susi
36-
-S, --SignedOutCallbackPath <SignedOutCallbackPath> The global signout callback (use with IndividualB2C auth).
36+
-socp, --signed-out-callback-path <signed-out-callback-path> The global signout callback (use with IndividualB2C auth).
3737
Type: string
3838
Default: /signout/B2C_1_susi
3939
-rp, --reset-password-policy-id <reset-password-policy-id> The reset password policy ID for this project (use with IndividualB2C auth).
@@ -72,11 +72,12 @@ Template options:
7272
-uld, --use-local-db Whether to use LocalDB instead of SQLite. This option only applies if --auth Individual or --auth IndividualB2C is specified.
7373
Type: bool
7474
Default: false
75-
-f, --framework <net6.0|net7.0> The target framework for the project.
75+
-f, --framework <net6.0|net7.0|net8.0> The target framework for the project.
7676
Type: choice
77+
net8.0 Target net8.0
7778
net7.0 Target net7.0
7879
net6.0 Target net6.0
79-
Default: net7.0
80+
Default: net8.0
8081
--called-api-url <called-api-url> URL of the API to call from the web app. This option only applies if --auth SingleOrg, --auth MultiOrg or --auth IndividualB2C is specified.
8182
Type: string
8283
Default: https://graph.microsoft.com/v1.0
@@ -88,4 +89,7 @@ Template options:
8889
Default: user.read
8990
--use-program-main Whether to generate an explicit Program class and Main method instead of top-level statements.
9091
Type: bool
91-
Default: false
92+
Default: false
93+
-S, --SignedOutCallbackPath <SignedOutCallbackPath> The global signout callback (use with IndividualB2C auth).
94+
Type: string
95+
Default: /signout/B2C_1_susi

src/Tests/dotnet-new.Tests/WebProjectsTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ public WebProjectsTests(WebProjectsFixture fixture, ITestOutputHelper log) : bas
2323
}
2424

2525
[Theory]
26-
[InlineData("emptyweb_cs-latest", "web")]
27-
[InlineData("mvc_cs-latest", "mvc")]
28-
[InlineData("mvc_fs-latest", "mvc", "-lang", "F#")]
29-
[InlineData("api_cs-latest", "webapi")]
26+
// TODO: Reenable after https://github.com/dotnet/sdk/issues/30033 is fixed
27+
// [InlineData("emptyweb_cs-latest", "web")]
28+
// [InlineData("mvc_cs-latest", "mvc")]
29+
// [InlineData("mvc_fs-latest", "mvc", "-lang", "F#")]
30+
// [InlineData("api_cs-latest", "webapi")]
3031
[InlineData("emptyweb_cs-60", "web", "-f", "net6.0")]
3132
[InlineData("mvc_cs-60", "mvc", "-f", "net6.0")]
3233
[InlineData("mvc_fs-60", "mvc", "-lang", "F#", "-f", "net6.0")]

src/Tests/xunit-runner/XUnitRunner.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<SDKCustomXUnitArguments Condition="'$(SDKCustomXUnitArguments)' == ''">-nocolor</SDKCustomXUnitArguments>
1111

12-
<TaskTargetFramework>netcoreapp3.1</TaskTargetFramework>
12+
<TaskTargetFramework>net6.0</TaskTargetFramework>
1313
<TaskTargetFramework Condition="'$(MSBuildRuntimeType)' != 'Core'">net472</TaskTargetFramework>
1414

1515
<SDKHelixCustomSdkTaskDll>$(ArtifactsDir)\bin\HelixTasks\$(Configuration)\$(TaskTargetFramework)\HelixTasks.dll</SDKHelixCustomSdkTaskDll>

src/WebSdk/Web/Sdk/Sdk.props

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ Copyright (c) .NET Foundation. All rights reserved.
6161
IsImplicitlyDefined="true" />
6262
</ItemGroup>
6363

64+
<!-- The RequestDelegateGenerator is bundled into the Microsoft.AspNetCore.App ref pack.-->
65+
<!-- We want this generator to be disabled by default so we remove it from the list of-->
66+
<!-- analyzers here. Since this depends on the analyzer having already been added to the-->
67+
<!-- `Analyzer` item group by previous tasks in the build, we must wrap this work in a-->
68+
<!-- target that executes right before the compilation loop.-->
69+
<Target Name="RemoveRequestDelegateGenerator" BeforeTargets="CoreCompile">
70+
<ItemGroup>
71+
<Analyzer
72+
Remove="@(Analyzer->HasMetadata('FileName')->WithMetadataValue('FileName', 'Microsoft.AspNetCore.Http.Generators'))"
73+
Condition="'$(Language)'=='C#' AND '$(EnableRequestDelegateGenerator)' != 'true'"/>
74+
</ItemGroup>
75+
</Target>
76+
6477
<ItemGroup Condition="'$(Language)' == 'C#' AND ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable')">
6578
<Using Include="System.Net.Http.Json" />
6679
<Using Include="Microsoft.AspNetCore.Builder" />

0 commit comments

Comments
 (0)