Run ASP.NET Core Apps on the .NET Framework
Status of ASP.NET Core on .NET Framework
The last important Microsoft announcement concerning the future of ASP.NET Core 2.1 was that it would stop supporting new versions of ASP.NET Core on the .NET Framework. Whilst we disagreed against this decision which would’ve put out a large class of the existing ecosystems from participating in the new ASP.NET Core development model and many from staged migrations to .NET Core from commencing, we’re happy to see ASP.NET Core 2.1 LTS will enjoy the same indefinite level of support as the rest of the .NET Framework - which should come as great news to the 1/3 of our Customers who are still creating new ASP.NET Core on FX Project Templates.
Whilst this announcement sends a clear message that new development on .NET Framework has effectively been put on product life support, ASP.NET Core 2.1 LTS is still a great rock-solid platform to build on if you’re unable to jump directly to .NET Core immediately or if you want to get off .NET Core’s major version release train and build upon a stable LTS platform.
ASP.NET Core - still our top recommendation for .NET Framework
If you need to stay on the .NET Framework, we’d still recommend using the newer ASP.NET Core 2.1 over classic ASP.NET System.Web projects as it’s cleaner, lighter, more flexible and future proof. Unlike Microsoft web frameworks, ServiceStack is a single code-base which supports running on multiple platforms so your ServiceStack Services can enjoy near perfect source-code compatibility when and if you choose to move to .NET Core in future.
Whilst Microsoft is stopping new development of ASP.NET Core on .NET Framework, we’re not, our supported packages have standardized to multi-target both .NET v4.5+ and .NET Standard 2.0 which is supported natively on ASP.NET Core 2.1.
Future proofed and continually developed
This includes our own innovations that we continue to invest in like #Script (fka ServiceStack Templates) naturally support .NET Framework and .NET Core and runs everywhere ServiceStack does including within classic ASP.NET MVC Controllers which wasn’t a design goal but was a natural consequence of developing clean libraries without external dependencies or reliance on external tooling.
This is to say that ASP.NET Core 2.1 LTS is still a fantastic rock-solid platform to run your .NET Framework workloads when you need to which will continue to receive enhancements and new features with each ServiceStack release courtesy of being derived from the same shared code-base which will enable seamless migrations to .NET Core should you wish to in future.
Start from pre-configured Project Templates
Ultimately you’ll miss out on niceties like the Microsoft.AspNetCore.App
meta-package, as a result we recommend starting from one of our ASP.NET Core Framework project Templates
which by convention all have the
|ASP.NET Core Framework Templates|
|web-corefx||.NET Framework ASP.NET Core Website|
|vue-lite-corefx||.NET Framework ASP.NET Core lite (npm-free) Vue SPA using TypeScript|
|react-lite-corefx||.NET Framework ASP.NET Core lite (npm-free) React SPA using TypeScript|
|sharp-corefx||.NET Framework ASP.NET Core Templates Bootstrap Website|
|razor-corefx||.NET Framework ASP.NET Core Website with ServiceStack.Razor|
|mvc-corefx||.NET Framework ASP.NET Core MVC Website|
|selfhost-corefx||.NET Framework ASP.NET Core self-hosting Console App|
This will let you create an ASP.NET Core App running on the .NET Framework v4.7 using web new with:
$ dotnet tool install --global web $ web new web-corefx AcmeNetFx
Which can then be opened in your preferred VS.NET or Project Rider C# IDE.
Reference .Core packages
The primary difference between ASP.NET Core Apps on .NET Core 2.1 vs .NET Framework is needing to reference the
.Core packages to force referencing ServiceStack .NET Standard 2.0 libraries, which otherwise when installed in a .NET Framework project would install
net45 libraries. The differences between the 2 builds include:
net45- Contains support for running ASP.NET Web or Self-Hosting HttpListener App Hosts
netstandard2.0- Contains support for only running on ASP.NET Core App Hosts
In order to run ASP.NET Core Apps on the .NET Framework it needs to only reference
.Core NuGet packages which contains only the .NET Standard 2.0 builds. Currently the list of
.Core packages which contains only .NET Standard 2.0 builds include:
Ultimately support for whether a .NET Standard 2.0 library will run on the .NET Framework depends on whether external dependencies also support this scenario which as it’s a more niche use-case, will be a less tested scenario.
Resolving Runtime Assembly Loading Issues
Many of Microsoft’s core .NET Standard 2.0 packages have been reported to have runtime Assembly loading issues
FileNotFoundException “Could not load file or assembly …” Exceptions in .NET Framework projects, including:
Some solutions that have been known to resolve these issues include:
- Adding the package, e.g.
System.Runtime.CompilerServices.Unsafereference directly on the Host project, for netstandard the package is NETStandard.Library.NETFramework or installing .NET Core 2.0 SDK.
- Manually Adding Binding Redirect, see:
- If you had an existing binding redirect, try removing it
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>to your project’s .csproj
- Uninstalling and Reinstalling the problem packages from your projects
- Clean Solution and remove project artifacts, including Nuget
- Upgrading to the latest version of the .NET Framework (v4.7.2+)
Many of these issues is the result of older .NET Frameworks like .NET v4.6.1 not properly supporting .NET Standard 2.0 which is mostly resolved by installing .NET Framework v4.7.1+.