Search code examples
c#.netasp.net-coredotnet-cli

Create new ASP.NET Core project that targets .NET Framework by DotNet CLI


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.


Solution

  • 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>