Use ASP.NET Core 1.1 with .NET 4.6 (without Visual Studio)
March 14, 2017 · 2 minute read
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.
dotnet new mvc
Take a look at the folder and you’ll see a *.csproj file.
By default the .csproj file will target a version of .NET Core (either 1.0 or 1.1 depending on your set-up).
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" /> <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" /> </ItemGroup> </Project>
It’s a simple change to flip this over to target the full framework.
<PropertyGroup> <TargetFramework>net46</TargetFramework> </PropertyGroup>
Once you’ve saved that, head back to the console and restore any missing NuGet packages.
Then run the app.
Now you can reference .NET 4.x packages but write your web app using ASP.NET Core.