简体   繁体   English

将 class 库项目升级到 .net 标准 2.1,其中 .net 框架 4.X 项目已引用该标准

[英]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.从一个被 13 个项目引用的 class 库开始。 I need to upgrade my class library project .NET Framework 4.5 to .NET Standard 2.1 .我需要将我的 class 库项目.NET Framework 4.5升级到.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这个 class 库被.NET Framework 4.5的项目引用,它的抛出错误是它无法访问.NET Standard 2.1

Project 'abc.csproj' targets 'netstandard2.1'.项目“abc.csproj”以“netstandard2.1”为目标。 It cannot be referenced by a project that targets '.NETFramework,Version=v4.5'.它不能被以 '.NETFramework,Version=v4.5' 为目标的项目引用。

How to resolve this problem?如何解决这个问题? Upgrading all those 13 projects is not possible at the same time.不可能同时升级所有这 13 个项目。


EDIT: Following comments, if I convert lib to .netstandard1.1 then errors start coming in the library itself:编辑:根据评论,如果我将 lib 转换为.netstandard1.1 ,那么库本身就会出现错误: 在此处输入图像描述

After downgrading lib to .netstandard1.1 , following on NetStandard 1.4 does not allow decorating class with [DataContract] .将 lib 降级到.netstandard1.1后,在NetStandard 1.4 之后不允许使用 [DataContract] 装饰 class I saw this post and added this package System.Runtime.Serialization.Primitives :我看到这篇文章并添加了这个 package System.Runtime.Serialization.Primitives 在此处输入图像描述

I even added reference to older dll but, still getting error:我什至添加了对旧 dll 的引用,但是仍然出现错误: 在此处输入图像描述

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 .起初,OP 想将库的框架更改为.NET Standard 2.1 ,同时在.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 .官方文档中所述, .NET Standard 2.1不遵循.NET Framework Latest you can get is .NET Standard 2.0 with .NET Framework 4.6.1 .您可以获得的最新版本是.NET Standard 2.0.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.此问题的解决方案是将公共库项目降级到.NET Standard 1.1 ,其他应用程序项目应该能够链接到此。

Next iteration (after downgrading to .NET Standard 1.1 ) brought issue related to "unknown classes" and VS/compiler asking for adding reference.下一次迭代(在降级到.NET Standard 1.1之后)带来了与“未知类”和 VS/编译器要求添加参考相关的问题。 There was already existing question , answer is to download NuGet package related to the data serializers.已经存在问题,答案是下载与数据序列化器相关的 NuGet package。

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 ).不可能从 Nuget 获取一个Attribute并检查“相同属性/相同名称”但来自不同来源(系统程序集 - > System.Runtime.Serialization )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将旧的.Net 35项目升级到4.x->在哪里下载Reactive Framework 4.x - Upgrading old .Net 35 Project to 4.x -> Where do I download Reactive Framework 4.x 在Core 2.0 Web API项目中引用了.net Framework 4.x程序集的app.config迁移? - app.config migration for .net framework 4.x assemblies referenced in Core 2.0 Web API project? .NET Framework 4.7项目中的.NET标准类库 - .NET Standard Class Library in .NET Framework 4.7 project 目标.NET 4.x和.NET Standard 2.0 - Target .NET 4.x and .NET Standard 2.0 库升级到 .net 标准 2.1 - library upgrade to .net standard 2.1 EntityFramwork 与 .net 框架 4.7.2 项目和 .net 标准 2.0 项目的兼容性 - EntityFramwork compatibility with .net framework 4.7.2 projects and .net standard 2.0 project Droid项目中引用的.NET Standard 2库中的HttpClient实现 - HttpClient implementation in .NET Standard 2 library which is referenced in Droid project .NET Framework 4.6.1应用程序具有引用.NET Standard 1.4类库的错误 - .NET Framework 4.6.1 application has errors referencing .NET Standard 1.4 class library 我可以使用.Net标准库中的PowerShell类在.Net Framework项目(exe)中使用吗 - Can I use PowerShell class in .Net Standard library to use in .Net Framework project (exe) 引用的.NET标准项目中的多个DLL - Multiple DLLs from referenced .NET Standard projects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM