简体   繁体   中英

Upgrading class library project to .net standard 2.1 where this has been referenced by .net framework 4.X projects

We are upgrading our solution of multiple projects. Starting with one class library which is been referenced by 13 projects. I need to upgrade my class library project .NET Framework 4.5 to .NET Standard 2.1 . Here the problem is:

This class library is being referenced by projects of .NET Framework 4.5 and its throwing error that it can't access .NET Standard 2.1 lib

Project 'abc.csproj' targets 'netstandard2.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.5'.

How to resolve this problem? Upgrading all those 13 projects is not possible at the same time.


EDIT: Following comments, if I convert lib to .netstandard1.1 then errors start coming in the library itself: 在此处输入图像描述

After downgrading lib to .netstandard1.1 , following on NetStandard 1.4 does not allow decorating class with [DataContract] . I saw this post and added this package System.Runtime.Serialization.Primitives : 在此处输入图像描述

I even added reference to older dll but, still getting error: 在此处输入图像描述

Adding answer as we've iterated through the comments. At first OP wanted to change framework of library to .NET Standard 2.1 while having other apps under .NET Framework 4.5 .

Unfortunately, this is not possible. As specified in the official documentation , .NET Standard 2.1 is not following along with .NET Framework . Latest you can get is .NET Standard 2.0 with .NET Framework 4.6.1 . Solution for this issue is to downgrade common library project to .NET Standard 1.1 , other app projects should be able to link to this.

Next iteration (after downgrading to .NET Standard 1.1 ) brought issue related to "unknown classes" and VS/compiler asking for adding reference. There was already existing question , answer is to download NuGet package related to the data serializers.

If your code in end-applications are also using classes/attributes from the affected assembly, you must make a cleanup. So that all code references the only single version of source. It is not possible to have one Attribute taken from Nuget and check for "same attribute/same name" but from different source (system assembly -> System.Runtime.Serialization ).

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