@@ -48,6 +48,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
48
48
public static final String GENERATE_BODY = "generateBody" ;
49
49
public static final String BUILD_TARGET = "buildTarget" ;
50
50
public static final String MODEL_CLASS_MODIFIER = "modelClassModifier" ;
51
+ public static final String TARGET_FRAMEWORK = "targetFramework" ;
51
52
52
53
public static final String PROJECT_SDK = "projectSdk" ;
53
54
public static final String SDK_WEB = "Microsoft.NET.Sdk.Web" ;
@@ -68,7 +69,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
68
69
protected int serverPort = 8080 ;
69
70
protected String serverHost = "0.0.0.0" ;
70
71
protected CliOption swashbuckleVersion = new CliOption (SWASHBUCKLE_VERSION , "Swashbuckle version: 3.0.0, 4.0.0, 5.0.0" );
71
- protected CliOption aspnetCoreVersion = new CliOption (ASPNET_CORE_VERSION , "ASP.NET Core version: 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)" );
72
+ protected CliOption aspnetCoreVersion = new CliOption (ASPNET_CORE_VERSION , "ASP.NET Core version: 5.0, 3.1, 3.0, 2.2, 2.1, 2.0 (deprecated)" );
72
73
private CliOption classModifier = new CliOption (CLASS_MODIFIER , "Class Modifier for controller classes: Empty string or abstract." );
73
74
private CliOption operationModifier = new CliOption (OPERATION_MODIFIER , "Operation Modifier can be virtual or abstract" );
74
75
private CliOption modelClassModifier = new CliOption (MODEL_CLASS_MODIFIER , "Model Class Modifier can be nothing or partial" );
@@ -123,7 +124,7 @@ public AspNetCoreServerCodegen() {
123
124
modelTemplateFiles .put ("model.mustache" , ".cs" );
124
125
apiTemplateFiles .put ("controller.mustache" , ".cs" );
125
126
126
- embeddedTemplateDir = templateDir = "aspnetcore/2.1 " ;
127
+ embeddedTemplateDir = templateDir = "aspnetcore/3.0 " ;
127
128
128
129
// contextually reserved words
129
130
// NOTE: C# uses camel cased reserved words, while models are title cased. We don't want lowercase comparisons.
@@ -190,6 +191,7 @@ public AspNetCoreServerCodegen() {
190
191
aspnetCoreVersion .addEnum ("2.2" , "ASP.NET Core 2.2" );
191
192
aspnetCoreVersion .addEnum ("3.0" , "ASP.NET Core 3.0" );
192
193
aspnetCoreVersion .addEnum ("3.1" , "ASP.NET Core 3.1" );
194
+ aspnetCoreVersion .addEnum ("5.0" , "ASP.NET Core 5.0" );
193
195
aspnetCoreVersion .setDefault ("3.1" );
194
196
aspnetCoreVersion .setOptValue (aspnetCoreVersion .getDefault ());
195
197
addOption (aspnetCoreVersion .getOpt (), aspnetCoreVersion .getDescription (), aspnetCoreVersion .getOptValue ());
@@ -367,7 +369,7 @@ public void processOpts() {
367
369
supportingFiles .add (new SupportingFile ("gitignore" , packageFolder , ".gitignore" ));
368
370
supportingFiles .add (new SupportingFile ("validateModel.mustache" , packageFolder + File .separator + "Attributes" , "ValidateModelStateAttribute.cs" ));
369
371
supportingFiles .add (new SupportingFile ("typeConverter.mustache" , packageFolder + File .separator + "Converters" , "CustomEnumConverter.cs" ));
370
- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
372
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5.0" ) ) {
371
373
supportingFiles .add (new SupportingFile ("OpenApi" + File .separator + "TypeExtensions.mustache" , packageFolder + File .separator + "OpenApi" , "TypeExtensions.cs" ));
372
374
}
373
375
supportingFiles .add (new SupportingFile ("Project.csproj.mustache" , packageFolder , packageName + ".csproj" ));
@@ -535,7 +537,7 @@ private void setBuildTarget() {
535
537
private void setAspnetCoreVersion (String packageFolder ) {
536
538
setCliOption (aspnetCoreVersion );
537
539
538
- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
540
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5.0" ) ) {
539
541
compatibilityVersion = null ;
540
542
} else if ("2.0" .equals (aspnetCoreVersion .getOptValue ())) {
541
543
compatibilityVersion = null ;
@@ -552,6 +554,7 @@ private void setAspnetCoreVersion(String packageFolder) {
552
554
553
555
private String determineTemplateVersion (String frameworkVersion ) {
554
556
switch (frameworkVersion ) {
557
+ case "5.0" :
555
558
case "3.1" :
556
559
return "3.0" ;
557
560
@@ -593,17 +596,25 @@ private void setIsFramework() {
593
596
LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing to use frameworkReference instead of packageReference " );
594
597
useFrameworkReference = true ;
595
598
additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
599
+ additionalProperties .put (TARGET_FRAMEWORK , "netcoreapp" + aspnetCoreVersion );
600
+ } else if (aspnetCoreVersion .getOptValue ().startsWith ("5." )) {// default, do nothing
601
+ LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing to use frameworkReference instead of packageReference " );
602
+ useFrameworkReference = true ;
603
+ additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
604
+ additionalProperties .put (TARGET_FRAMEWORK , "net5.0" );
596
605
} else {
597
606
if (additionalProperties .containsKey (USE_FRAMEWORK_REFERENCE )) {
598
607
useFrameworkReference = convertPropertyToBooleanAndWriteBack (USE_FRAMEWORK_REFERENCE );
599
608
} else {
600
609
additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
601
610
}
611
+ additionalProperties .put (TARGET_FRAMEWORK , "netcoreapp" + aspnetCoreVersion );
602
612
}
603
613
}
604
614
605
615
private void setUseNewtonsoft () {
606
616
if (aspnetCoreVersion .getOptValue ().startsWith ("2." )) {
617
+ LOGGER .warn ("ASP.NET core version 2.X support has been deprecated. Please use ASP.NET core version 3.1 instead" );
607
618
LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so staying on default json library." );
608
619
useNewtonsoft = false ;
609
620
additionalProperties .put (USE_NEWTONSOFT , useNewtonsoft );
@@ -617,7 +628,7 @@ private void setUseNewtonsoft() {
617
628
}
618
629
619
630
private void setUseEndpointRouting () {
620
- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
631
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5." ) ) {
621
632
LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so switching to old style endpoint routing." );
622
633
useDefaultRouting = false ;
623
634
additionalProperties .put (USE_DEFAULT_ROUTING , useDefaultRouting );
@@ -633,7 +644,7 @@ private void setUseEndpointRouting() {
633
644
private void setSwashbuckleVersion () {
634
645
setCliOption (swashbuckleVersion );
635
646
636
- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
647
+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5." ) ) {
637
648
LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing default Swashbuckle version to 5.0.0." );
638
649
swashbuckleVersion .setOptValue ("5.0.0" );
639
650
additionalProperties .put (SWASHBUCKLE_VERSION , swashbuckleVersion .getOptValue ());
0 commit comments