0

I try to create a new ASP.NET Core project that target the classic .NET Framework. The template web and webapi have the option framework, but this don't accept .NET Framework value like :

dotnet new web --name MyWebProject --framework net48

Error: Invalid parameter(s):
--framework net48
'net48' is not a valid value for --framework (Framework).

How create ASP.NET Core project that targets .NET Framework from DotNet CLI?

If it isn't possible, do you know a solution to do this in command line?

PS : I know the Visual Studio template ASP.NET Core empty let select .NET Framework. I search a solution from command line, preferably with DotNet CLI.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
vernou
  • 6,818
  • 5
  • 30
  • 58
  • You **CANNOT** by definition create a **.NET Core** project that targets the "full, classic" .NET Framework (neither from the CLI, nor in Visual Studio). That would no longer be a **.NET Core** project - but instead a "regular" .NET project..... the question is more: **WHY** would you want to do this?? – marc_s Apr 11 '21 at 14:44
  • *I know the Visual Studio template ASP.NET Core empty let select .NET Framework* - that statement is **false** - if you create a new ASP.NET Core (empty) project, you can **only** select the various .NET Core runtimes - any that you have installed - but you **CANNOT** pick the full, classic .NET 4.8 as runtime.... – marc_s Apr 11 '21 at 15:50
  • @marc_s, ASP.NET Core is a web framework in .NET Standard. The runtime choice is just a line in csproj. Yes, the web framework's name can be misleading... – vernou Apr 12 '21 at 07:10

2 Answers2

3

I used this to create ASP.NET Core empty Web App that targets 4.7.1:

dotnet new web --target-framework-override net471

I saw it there. The generated project file looks like this:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
  </ItemGroup>

</Project>
vernou
  • 6,818
  • 5
  • 30
  • 58
K. B.
  • 3,342
  • 3
  • 19
  • 32
1

There is no option to set .net frameworks with a default template. You can view the framework's options by running: dotnet new web --help:

image

Dmitrii
  • 11
  • 3