Skip to content

Commit 84bd0ec

Browse files
API template updates (#49394)
* Default webapi template to use minimal APIs & introduce option to use controllers * Rename api template to webapiaot and remove aot option as it's always aot now
1 parent ff800a5 commit 84bd0ec

File tree

19 files changed

+126
-193
lines changed

19 files changed

+126
-193
lines changed

src/ProjectTemplates/Shared/ArgConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Templates.Test.Helpers;
66
internal static class ArgConstants
77
{
88
public const string UseProgramMain = "--use-program-main";
9-
public const string UseMinimalApis = "--use-minimal-apis";
9+
public const string UseControllers = "--use-controllers";
1010
public const string Pwa = "--pwa";
1111
public const string CallsGraph = "--calls-graph";
1212
public const string CalledApiUrl = "--called-api-url";

src/ProjectTemplates/Web.ProjectTemplates/Api-CSharp.csproj.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">true</NoDefaultLaunchSettingsFile>
88
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.WebApplication1</RootNamespace>
9-
<!--#if (NativeAot) -->
109
<InvariantGlobalization>true</InvariantGlobalization>
1110
<PublishAot>true</PublishAot>
12-
<!--#endif -->
1311
</PropertyGroup>
1412

1513
</Project>

src/ProjectTemplates/Web.ProjectTemplates/content/Api-CSharp/.template.config/dotnetcli.host.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
"UseProgramMain": {
2222
"longName": "use-program-main",
2323
"shortName": ""
24-
},
25-
"NativeAot": {
26-
"longName": "aot",
27-
"shortName": ""
2824
}
2925
},
3026
"usageExamples": [

src/ProjectTemplates/Web.ProjectTemplates/content/Api-CSharp/.template.config/ide.host.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
"isVisible": true,
1010
"persistenceScope": "shared",
1111
"persistenceScopeName": "Microsoft"
12-
},
13-
{
14-
"id": "NativeAot",
15-
"isVisible": true
1612
}
1713
]
1814
}

src/ProjectTemplates/Web.ProjectTemplates/content/Api-CSharp/.template.config/template.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
"author": "Microsoft",
44
"classifications": [
55
"Web",
6-
"API"
6+
"Web API",
7+
"API",
8+
"Service"
79
],
8-
"name": "ASP.NET Core API",
10+
"name": "ASP.NET Core Web API (native AOT)",
911
"generatorVersions": "[1.0.0.0-*)",
10-
"description": "A project template for creating an ASP.NET Core API application.",
12+
"description": "A project template for creating a RESTful Web API using ASP.NET Core minimal APIs published as native AOT.",
1113
"groupIdentity": "Microsoft.Web.Api",
1214
"precedence": "9000",
1315
"identity": "Microsoft.Web.Api.CSharp.8.0",
14-
"shortName": "api",
16+
"shortName": "webapiaot",
1517
"tags": {
1618
"language": "C#",
1719
"type": "project"
@@ -128,13 +130,6 @@
128130
"defaultValue": "false",
129131
"displayName": "Do not use _top-level statements",
130132
"description": "Whether to generate an explicit Program class and Main method instead of top-level statements."
131-
},
132-
"NativeAot" : {
133-
"type": "parameter",
134-
"datatype": "bool",
135-
"defaultValue": "false",
136-
"displayName": "Enable _native AOT publish",
137-
"description": "Whether to enable the project for publishing as native AOT."
138133
}
139134
},
140135
"primaryOutputs": [

src/ProjectTemplates/Web.ProjectTemplates/content/Api-CSharp/Program.Main.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#if NativeAot
21
using System.Text.Json.Serialization;
32

4-
#endif
53
namespace Company.ApiApplication1;
64

75
public class Program
@@ -10,13 +8,11 @@ public static void Main(string[] args)
108
{
119
var builder = WebApplication.CreateSlimBuilder(args);
1210

13-
#if (NativeAot)
1411
builder.Services.ConfigureHttpJsonOptions(options =>
1512
{
1613
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
1714
});
1815

19-
#endif
2016
var app = builder.Build();
2117

2218
var sampleTodos = new Todo[] {
@@ -40,7 +36,6 @@ public static void Main(string[] args)
4036

4137
public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);
4238

43-
#if (NativeAot)
4439
[JsonSerializable(typeof(Todo[]))]
4540
internal partial class AppJsonSerializerContext : JsonSerializerContext
4641
{

src/ProjectTemplates/Web.ProjectTemplates/content/Api-CSharp/Program.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
#if (NativeAot)
21
using System.Text.Json.Serialization;
32

4-
#endif
53
var builder = WebApplication.CreateSlimBuilder(args);
64

7-
#if (NativeAot)
85
builder.Services.ConfigureHttpJsonOptions(options =>
96
{
107
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
118
});
129

13-
#endif
1410
var app = builder.Build();
1511

1612
var sampleTodos = new Todo[] {
@@ -32,7 +28,6 @@
3228

3329
public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);
3430

35-
#if (NativeAot)
3631
[JsonSerializable(typeof(Todo[]))]
3732
internal partial class AppJsonSerializerContext : JsonSerializerContext
3833
{

src/ProjectTemplates/Web.ProjectTemplates/content/GrpcService-CSharp/.template.config/template.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"author": "Microsoft",
44
"classifications": [
55
"Web",
6-
"gRPC"
6+
"gRPC",
7+
"API",
8+
"Service"
79
],
810
"name": "ASP.NET Core gRPC Service",
911
"generatorVersions": "[1.0.0.0-*)",
10-
"description": "A project template for creating a gRPC ASP.NET Core service.",
12+
"description": "A project template for creating a gRPC service using ASP.NET Core, with optional support for publishing as native AOT.",
1113
"groupIdentity": "Microsoft.Web.Grpc",
1214
"precedence": "9800",
1315
"identity": "Microsoft.Grpc.Service.CSharp.8.0",

src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/.template.config/dotnetcli.host.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
},
77
"UseMinimalAPIs": {
88
"longName": "use-minimal-apis",
9-
"shortName": "minimal"
9+
"shortName": "minimal",
10+
"isHidden": true
11+
},
12+
"UseControllers": {
13+
"longName": "use-controllers",
14+
"shortName": "controllers"
1015
},
1116
"AADInstance": {
1217
"longName": "aad-instance",

src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/.template.config/ide.host.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@
2626
"overrideDefaultText": true
2727
},
2828
"invertBoolean": true,
29-
"isVisible": true,
29+
"isVisible": false,
3030
"defaultValue": "true",
3131
"persistenceScope": "templateGroup"
3232
},
33+
{
34+
"id": "UseControllers",
35+
"name": {
36+
"text": "Use controllers",
37+
"overrideDefaultText": true
38+
},
39+
"isVisible": true,
40+
"defaultValue": "false",
41+
"persistenceScope": "templateGroup"
42+
},
3343
{
3444
"id": "UseProgramMain",
3545
"isVisible": true,

0 commit comments

Comments
 (0)