Can a .NET Core app on Windows also access system.

2019-07-12 12:40发布

问题:

We have a large ASP.NET application, that we are working to move toward .NET Core. The main goal is to self host (bye bye IIS, hello xcopy deploy!).

We have a path to migrate the app to Razor (several hundred aspx files), and this looks good (we were mostly on MVC, so we only have a few old legacy-asp.net pieces which we are redoing to MVC).

However, we have a large stack of third party libs that are .NET 4.6 based. We are stuck with most of these libs. These libs are hard coded to system.web for a number of functions. We cannot change this.

So the question: If I stick to running my .NET Core animal on Windows, can I, in process, also reference .NET 4.6/4.7 ?

(No, we are not going to microservices, please don't propose that.)

回答1:

ASP.NET Core are a set of libraries that run on both .NET Core and .NET Framework.

This means you can create an ASP.NET Core application that runs on .NET Framework and keep using all the stuff that is in .NET Framework. This can be done by creating a new ASP.NET Core application and editing the .csproj file to set TargetFramework from e.g. netcoreapp2.0 to net472 and replacing the Microsoft.AspNetCore.All metapackage with individual NuGet packages containing the ASP.NET Core libraries (Microsoft.AspNetCore etc.).

While this also gives you access to using types in System.Web, this may not be useful since the ASP.NET Core application does not run in IIS, so e.g. HttpContext from System.Web cannot be used (since there is no IIS/ASP.NET HTTP context).

So bottom line, it depends on what functionality of System.Web the libraries you are using depend on.