How To Specify Framework When Running ASPNET Core Apps

How To Specify Framework When Running ASPNET Core Apps

In .NET Core, you can target multiple frameworks from the same application. Where there are incompatibilities, you can use precompiler directives, like so:

However, if you have this in an application that also runs “netcoreapp1.0” it will probably run with that by default. To force it to run using .NET Framework 4.6.1 (or whatever version you’re using), you can switch it in Visual Studio using the dropdown menu next to IIS Express, as shown here:

FrameworkSelectorVisualStudio

If you’re running the application from the command line interface (dotnet run), you can specify the framework by using the -f directive:

With that, you should be able to test out your framework specific code blocks!