@@ -48,6 +48,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
4848 public static final String GENERATE_BODY = "generateBody" ;
4949 public static final String BUILD_TARGET = "buildTarget" ;
5050 public static final String MODEL_CLASS_MODIFIER = "modelClassModifier" ;
51+ public static final String TARGET_FRAMEWORK = "targetFramework" ;
5152
5253 public static final String PROJECT_SDK = "projectSdk" ;
5354 public static final String SDK_WEB = "Microsoft.NET.Sdk.Web" ;
@@ -68,7 +69,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
6869 protected int serverPort = 8080 ;
6970 protected String serverHost = "0.0.0.0" ;
7071 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)" );
7273 private CliOption classModifier = new CliOption (CLASS_MODIFIER , "Class Modifier for controller classes: Empty string or abstract." );
7374 private CliOption operationModifier = new CliOption (OPERATION_MODIFIER , "Operation Modifier can be virtual or abstract" );
7475 private CliOption modelClassModifier = new CliOption (MODEL_CLASS_MODIFIER , "Model Class Modifier can be nothing or partial" );
@@ -123,7 +124,7 @@ public AspNetCoreServerCodegen() {
123124 modelTemplateFiles .put ("model.mustache" , ".cs" );
124125 apiTemplateFiles .put ("controller.mustache" , ".cs" );
125126
126- embeddedTemplateDir = templateDir = "aspnetcore/2.1 " ;
127+ embeddedTemplateDir = templateDir = "aspnetcore/3.0 " ;
127128
128129 // contextually reserved words
129130 // NOTE: C# uses camel cased reserved words, while models are title cased. We don't want lowercase comparisons.
@@ -190,6 +191,7 @@ public AspNetCoreServerCodegen() {
190191 aspnetCoreVersion .addEnum ("2.2" , "ASP.NET Core 2.2" );
191192 aspnetCoreVersion .addEnum ("3.0" , "ASP.NET Core 3.0" );
192193 aspnetCoreVersion .addEnum ("3.1" , "ASP.NET Core 3.1" );
194+ aspnetCoreVersion .addEnum ("5.0" , "ASP.NET Core 5.0" );
193195 aspnetCoreVersion .setDefault ("3.1" );
194196 aspnetCoreVersion .setOptValue (aspnetCoreVersion .getDefault ());
195197 addOption (aspnetCoreVersion .getOpt (), aspnetCoreVersion .getDescription (), aspnetCoreVersion .getOptValue ());
@@ -367,7 +369,7 @@ public void processOpts() {
367369 supportingFiles .add (new SupportingFile ("gitignore" , packageFolder , ".gitignore" ));
368370 supportingFiles .add (new SupportingFile ("validateModel.mustache" , packageFolder + File .separator + "Attributes" , "ValidateModelStateAttribute.cs" ));
369371 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" ) ) {
371373 supportingFiles .add (new SupportingFile ("OpenApi" + File .separator + "TypeExtensions.mustache" , packageFolder + File .separator + "OpenApi" , "TypeExtensions.cs" ));
372374 }
373375 supportingFiles .add (new SupportingFile ("Project.csproj.mustache" , packageFolder , packageName + ".csproj" ));
@@ -535,7 +537,7 @@ private void setBuildTarget() {
535537 private void setAspnetCoreVersion (String packageFolder ) {
536538 setCliOption (aspnetCoreVersion );
537539
538- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
540+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5.0" ) ) {
539541 compatibilityVersion = null ;
540542 } else if ("2.0" .equals (aspnetCoreVersion .getOptValue ())) {
541543 compatibilityVersion = null ;
@@ -552,6 +554,7 @@ private void setAspnetCoreVersion(String packageFolder) {
552554
553555 private String determineTemplateVersion (String frameworkVersion ) {
554556 switch (frameworkVersion ) {
557+ case "5.0" :
555558 case "3.1" :
556559 return "3.0" ;
557560
@@ -593,17 +596,25 @@ private void setIsFramework() {
593596 LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing to use frameworkReference instead of packageReference " );
594597 useFrameworkReference = true ;
595598 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" );
596605 } else {
597606 if (additionalProperties .containsKey (USE_FRAMEWORK_REFERENCE )) {
598607 useFrameworkReference = convertPropertyToBooleanAndWriteBack (USE_FRAMEWORK_REFERENCE );
599608 } else {
600609 additionalProperties .put (USE_FRAMEWORK_REFERENCE , useFrameworkReference );
601610 }
611+ additionalProperties .put (TARGET_FRAMEWORK , "netcoreapp" + aspnetCoreVersion );
602612 }
603613 }
604614
605615 private void setUseNewtonsoft () {
606616 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" );
607618 LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so staying on default json library." );
608619 useNewtonsoft = false ;
609620 additionalProperties .put (USE_NEWTONSOFT , useNewtonsoft );
@@ -617,7 +628,7 @@ private void setUseNewtonsoft() {
617628 }
618629
619630 private void setUseEndpointRouting () {
620- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
631+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5." ) ) {
621632 LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so switching to old style endpoint routing." );
622633 useDefaultRouting = false ;
623634 additionalProperties .put (USE_DEFAULT_ROUTING , useDefaultRouting );
@@ -633,7 +644,7 @@ private void setUseEndpointRouting() {
633644 private void setSwashbuckleVersion () {
634645 setCliOption (swashbuckleVersion );
635646
636- if (aspnetCoreVersion .getOptValue ().startsWith ("3." )) {
647+ if (aspnetCoreVersion .getOptValue ().startsWith ("3." ) || aspnetCoreVersion . getOptValue (). startsWith ( "5." ) ) {
637648 LOGGER .warn ("ASP.NET core version is " + aspnetCoreVersion .getOptValue () + " so changing default Swashbuckle version to 5.0.0." );
638649 swashbuckleVersion .setOptValue ("5.0.0" );
639650 additionalProperties .put (SWASHBUCKLE_VERSION , swashbuckleVersion .getOptValue ());
0 commit comments