If you want to try out ASP.NET Core but still target the full framework (e.g. 4.x) you can. All you need is a simple tweak to your .csproj file.

In earlier versions of .NET Core this change was made via project.json but Microsoft retired project.json in favour of an MSBuild compatible csproj file.

Why would I want to target .NET 4.x?

.NET Core is still in it’s infancy and you may find your favourite third party library hasn’t been ported over yet.

Or maybe you have existing applications which you still need to interact with and you’re not ready/able to move them over to .NET Core.

If so, you can build a shiny new ASP.NET Core app but still target .NET 4.x and reference other non Core projects.

If you’re using Visual Studio 2017 it’s easy to create a new project targeting the full framework but what if you’re using Visual Studio Code (or another code editor)? You can make the changes yourself.

Targeting .NET 4.x without Visual Studio

You don’t have to use Visual Studio 2017 to write ASP.NET Core apps that target the full framework. You can use this approach to edit/run and debug your code using Visual Studio Code.

First up, make sure you have the latest .NET core SDK installed.

At the time of writing that’s 1.1.

Now create a new mvc app in an empty folder.

Take a look at the folder and you'll see a *.csproj file.

<img src="/img/2017/03/NET-Core-new-MVC-project.png" alt="" />

By default the .csproj file will target a version of .NET Core (either 1.0 or 1.1 depending on your set-up).



It's a simple change to flip this over to target the full framework.

xml net46

Once you've saved that, head back to the console and restore any missing NuGet packages.

dotnet restore```

Then run the app.

dotnet run

Now you can reference .NET 4.x packages but write your web app using ASP.NET Core.

photo credit: jrladia Heartland Archery | Winnipeg via photopin (license)

Discuss on Twitter