简体   繁体   中英

Can .NET Standard 2.0 Class Library depend on .NET Framework 4.7.2?

In one of my .NET Framework projects, I introduced a new .NET Standard 2.0 project. This project has dependencies on some existing .NET Framework projects. I was wondering if this is right to do.? The reason I added a .NETStandard project is that we have plans to move the whole repository to .NET Core / Standard. Hence I thought, the new project we add can target .NET Standard. With .NET Standard project I get the new SDK style project file, package references, etc by default.

The consuming application is still .NET Framework.

Do I have to retarget the new project to .NET Framework 4.7.2 so that the project will have the above SDK style project file and package references but targets .NET Framework 4.7.2 now. It will then be as easy as changing the target framework when we move to .NET Core?

Depends on your purpose of introducing the Standard 2.0 project. Normally, you make a Standard when you need it to be accessible both from .NET Framework and Core. In your case, your Standard project won't be operable from Core under macOS or Linux.

Yes, this can be done.

https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0

.NET Framework compatibility mode Starting with .NET Standard 2.0, the .NET Framework compatibility mode was introduced. This compatibility mode allows .NET Standard projects to reference .NET Framework libraries as if they were compiled for .NET Standard. Referencing .NET Framework libraries doesn't work for all projects, such as libraries that use Windows Presentation Foundation (WPF) APIs.

This is necessary as an intermediate step for some projects, but in order to get to your final goal you will of course have to go all in on .net core which will require updating those projects not to use framework or they will crash at runtime.

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