How to create ASP .NET Core application for TargetFramework net5.0 and above in Visual Studio 2019

Viewed 39

I am developing a web server application with (asp) .net 5 and VisualStudio 2019.
The TargetFramework in all .csproj files is set to net5.0-windows.
Now I want the application to run also with .net 6 (without .net 5 installed). But I can't do a Visual Studio update to VS2022 at the moment.
When I start the current (compiled for .net 5) version on a system with only .net 6 installed, I get an error message from the .net Runtime:

Description: A .NET application failed.
...
Message: You must install or update .NET to run this application.
...
Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (x64)

Which seems logical, because in the .csproj file only the TargetFramework net5.0-windows is explicitly specified.

If I change the entry in the .csproj file to:

<TargetFrameworks>net5.0-windows;net6.0-windows</TargetFrameworks>

I get a compiler error:

Error NETSDK1045 The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.

Which is also logical, since the studio/compiler does not know version 6.0.

Is there any way to compile the application to run with frameworks net5.0 and above without having to explicitly specify the "above" ones?

0 Answers
Related