Background: The project we are wokring on consists of several solutions that share two libraries. Everything is written in .NET Framework 4.6.1
today. A goal for the project has been to adopt .NET Core
for new projects and being able to run web applications in Docker
.
With the new release of .NET Standard 2.1
and the fact that .NET Framework 4.8
will remain on .NET Standard 2.0
rather than implement .NET Standard 2.1
it felt like the right time to start. Immo Landwerth from Microsoft says this:
But what is also true is that the rate of innovation in .NET Framework has to slow down in order to reduce breakage. In that sense, you should generally expect that most new features will only become available on .NET Core (and derived platforms, such as Xamarin, Mono, and Unity as they build from the same sources as .NET Core).
https://blogs.msdn.microsoft.com/dotnet/2018/11/05/announcing-net-standard-2-1/
We would like to have access to new features in our new projects but do not want to convert every old project to .NET Core
. To keep compatibility between .NET Framework
and .NET Core
we decided to convert our shared libraries to .NET Standard 2.0
.
https://learn.microsoft.com/en-us/dotnet/standard/net-standard
This worked really well apart from the following dependencies:
1. System.Net.Http.WebRequestHandler - Solved
Used for client certificates like this:
WebRequestHandler requestHandler = new WebRequestHandler();
//Add certificate if setting exists
if (!string.IsNullOrEmpty(pushEvent?.CertificateThumbprint?.Thumbprint))
{
var certificate = certificateService.GetClientCertificate(pushEvent?.CertificateThumbprint?.Thumbprint);
if (certificate != null)
{
requestHandler.ClientCertificates.Add(certificate);
}
}
var client = new HttpClient(requestHandler);
I found a NuGet for it but it seems malicious. The package links to Microsoft documentation as Project Site and has misspelled Microsoft as author, Microsfot. Reported it so Microsoft can have a look at it.
https://www.nuget.org/packages/WebRequest.WebRequestHandler/
However it seems we can change WebRequestHandler
to HttpClientHandler
to get it working out of the box.
2. System.Runtime.Remoting.Messaging -> CallContext.LogicalGetData - Solved
Solved here: https://mcmap.net/q/406741/-net-core-equivalent-of-callcontext-logicalget-setdata
3. Microsoft.AspNet.Identity.EntityFramework.IdentityUser
We have a User Model that inherits from IdentityUser
.
public class AppUser : IdentityUser, ICurrentUser
{
public bool LocalEnvironment { get; set; }
public Guid? TokenId { get; set; }
}
4. Microsoft.AspNet.Identity.UserManager from assembly Microsoft.AspNet.Identity.Core
We keep our UserManager
shared between the projects. Container
is from SimpleInjector
which is compatible with .NET Standard 2.0
.
public class AppUserManager : UserManager<AppUser>
{
public AppUserManager(IUserStore<AppUser> store)
: base(store)
{
}
public static AppUserManager Create<AppContainer>() where AppContainer : Container, new()
{
var container = new AppContainer();
var store = container.GetInstance<IUserStore<AppUser>>();
var manager = new AppUserManager(store);
manager.UserValidator = new UserValidator<AppUser>(manager)
{
AllowOnlyAlphanumericUserNames = false
};
return manager;
}
}
If the EntityFramework NuGet
is installed in the shared library the warning below is present. We can't risk that.
Package 'EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
I have read about why they put IdentityUser
in the EF Library, IdentityUser
is very EF specific. However it makes porting to .NET Standard 2.0.
harder.
I have also read that ASP.NET Core 2.0
have removed the base IdentityUser
POCO (Plain Old CLR Object).
Microsoft.AspNetCore.Identity
and Microsoft.AspNetCore.Identity.EntityFrameworkCore
only has dependencies to .NETStandard 2.0
and can be installed without a warning. Do we need to upgrade Entity Framework and Identity on ASP.NET to Core or is there another way to get it working with .NET Standard
? Last step that we need to get it running.
https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x?view=aspnetcore-2.1
https://learn.microsoft.com/en-us/ef/efcore-and-ef6/side-by-side
EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1
will not start under linux, so if you need to run your website under linux, you need to switch from EF to EF core – StoppingIdentityUser
, it is from .NET Core which is not compatible with FW 4.6.1 (afaik), so you cannot share it across project. I dont get why you wrote aboutSimpleInjector
and how it is related to question, but you can only share .NET Standard libraries, and cannot share .NET Core with full framework. – StoppingSimpleInjector
was to describe what the inheritedContainer
was in the code example. The text is long but if you read it all I think it is pretty clear what the problem is and where our problems are. – Nordau