简体   繁体   中英

How to share the domain models between two different projects using different .NET version

I have a new ASP.NET core Web API application based on .NET 6 which shares the domain models with the Sitecore ASP.NET MVC application using .NET Framework 4.7.2 (legacy code). I want them to communicate with each other via Web API and the same models should be used for that. We wanted to create a new nuget package but unfortunately because of different .NET versions this is not compatible. Is there any way to not duplicate the models in both project but extract them somehow and reuse in both?

Yes, you can.

Create Class Library (.NET Standard 2.0) and put your models.

then reference 2 project to this class library.

Yes - create a class library targetting ".NET Standard 2.0" which contains your domain model classes.

It can be used in both .NET 4.7.2, as well as .NET 6 projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM