将.NET Standard库添加到4.7.1 lib中会添加大量的引用,其中一些损坏 [英] Adding .NET Standard libraries to 4.7.1 lib adds loads of references, some broken

查看:103
本文介绍了将.NET Standard库添加到4.7.1 lib中会添加大量的引用,其中一些损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我需要导入针对.NET Standard 2的库,因此我已将库升级至.NET 4.7.1,正如我从该MS视频中了解到的那样,应该避免此问题: https://www.youtube.com/watch?v=u67Eu_IgEMs

As I need to import a library targeting .NET Standard 2, I had upgraded my library to .NET 4.7.1, as I understood from this MS video that should avoid this issue: https://www.youtube.com/watch?v=u67Eu_IgEMs

但是,添加.NET标准现在会导致数十个System.xxx引用,而不是对.NET Standard的单个引用(根据视频)。

However, adding .NET standard now results in dozens of System.xxx references, rather than a single reference to .NET Standard (as per the video).

更糟仍然,已经添加了几个参考,但是基础文件似乎丢失了,生成警告,例如

警告找不到引用的组件 Microsoft.Win32.Primitives。
警告找不到引用的组件 System.IO.FileSystem。
警告找不到引用的组件 System.Security.Cryptography.X509Certificates。
警告找不到引用的组件'System.Globalization.Calendars'。

警告找不到引用的组件'System.Security.Cryptography.Encoding'。
警告找不到引用的组件 System.Security.Cryptography.Primitives。
警告找不到引用的组件 System.IO.Compression.ZipFile。
警告找不到引用的组件 System.Console。

我什至在视频中重新创建了演示项目,并得到了相同的结果-没有一个对.NET Standard的引用,而是许多DLL引用。

Worse still, several of the references have been added but the underlying file appears to be missing generating warnings, e.g. Warning The referenced component 'Microsoft.Win32.Primitives' could not be found. Warning The referenced component 'System.IO.FileSystem' could not be found. Warning The referenced component 'System.Security.Cryptography.X509Certificates' could not be found. Warning The referenced component 'System.Globalization.Calendars' could not be found.
Warning The referenced component 'System.Security.Cryptography.Encoding' could not be found. Warning The referenced component 'System.Security.Cryptography.Primitives' could not be found. Warning The referenced component 'System.IO.Compression.ZipFile' could not be found. Warning The referenced component 'System.Console' could not be found.
I even re-created the demo project in video and got the same result - no single reference to .NET Standard, lots of DLL references instead.

我尝试了NUGET update-package -reinstall ,并降级并升级到.NET标准2.0和2.0.1

I've tried a NUGET update-package -reinstall and downgraded and upgraded to .NET standard 2.0 and 2.0.1 as well

推荐答案

我为自己的问题创建的答案是:

The answer I'm creating for my own question is:

您的.NET Framework项目是否使用 packages.config ?如果是这样,请勿参考.NET Standard库。如果您引入.NET Standard,VS 2017中的包/引用/绑定重定向将被严重破坏。尝试修复它会导致更多问题(我浪费了几天的尝试时间)。

Does your .NET Framework project use packages.config ? If it does, DO NOT reference .NET Standard libraries. The package/reference/binding-redirect in VS 2017 is horribly broken if you introduce .NET Standard. Trying to fix it will cause more problems (I've wasted several days trying). Expect to have assemblies which don't load despite being present, lots of warnings and a broken app.

如果您使用 System.Net.Http,则尽管有程序集,但它们仍然存在但仍无法加载。

If you use System.Net.Http, plan on spending several days in Google and GitHub issues trying to get that to work.

如果能够升级到packageReferences,这应该可以解决问题。但是,如果您的项目包含导入内容的包,例如 JQuery Bootstrap ,请注意这些不再起作用,您会相反,将花费更多时间尝试修复这些引用,并迁移到 bower bower ,同时还要修复TypeScript编译。

If you are able to upgrade to packageReferences, this should fix the problem. But if your project contains packages that import content, like JQuery or Bootstrap be aware that these no longer work and you'll instead spend more time trying to fix those references and migrate to npm or bower, along with fixing TypeScript compilation too. No thanks.

理想情况下,您将使用2017年的csproj格式,但是与WinForms,ASP.NET或Windows Services不兼容-如果您拥有旧项目。

Ideally you'd be using the 2017 csproj format but that's not compatible with WinForms, ASP.NET or Windows Services - so tough if you've got a legacy project.

这篇关于将.NET Standard库添加到4.7.1 lib中会添加大量的引用,其中一些损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆