visual-studio-2017 - 使用 nuget 包时,有没有办法避免使用 netstandard 程序集来支持 PCL?

标签 visual-studio-2017 package nuget printer-control-language .net-standard-2.0

我有一个桌面应用程序和一个针对 .Net 框架 4.6.2 的简单类库。最近我注意到,当我在 VS 2017 (15.6.3) 中更新我的 nuget 包时,其中一个开始引入一些更新的 netstandard2.0 程序集。

我渴望有朝一日能够构建网络标准库。但是现在我更喜欢将相应的 PCL(在同一个 nuget 包中可用)作为依赖项而不是 netstandard 程序集引入我的项目。我追求的 nuget PCL 程序集的目标是“portable-net45+win8+wp8+wpa81”。

我不想要 netstandard2.0 程序集的原因是因为它会导致一堆 shim 程序集出现在输出目录中,而且鉴于我的应用程序类库本身并不针对 netstandard2.0,这有点过头了。发生的另一件事是 VS 开始为 System.ValueTuple 等不相关的包生成一堆版本冲突(编译器输出中的警告)。这似乎也与 shim 相关(shim 可能来自路径 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib)

下面是我开始看到的版本冲突示例。

Encountered conflict between 'Reference:System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL' and 'Reference:System.ValueTuple'. Choosing 'Reference:System.ValueTuple' because file version '4.6.26011.1' is greater than '4.6.25519.3'.



我希望这些只是警告,尽管非常可怕。我相信这些只是文件版本问题(与程序集版本无关),并且不认为它们会导致需要绑定(bind)重定向。即便如此,我会更高兴再次回到我的 PCL 并避免所有这些事情。我想一旦 .Net Framework 4.7.2 发布,我会更渴望使用和构建 netstandard 程序集。

我正在为 nuget 使用老式的 csproj 格式和 packages.config。似乎引入 netstandard2.0 位的 nuget 依赖项是 System.Composition。
System.Composition  1.1.0
System.Composition.AttributedModel  1.1.0
System.Composition.Convention   1.1.0
System.Composition.Hosting  1.1.0
System.Composition.Runtime  1.1.0
System.Composition.TypedParts   1.1.0
System.ValueTuple   4.4.0

希望这很清楚。我此时的解决方法是创建另一个面向 .Net 4.5 的类库,引入 System.Composition nuget 依赖项,运行 update-package,然后将包引用从 .Net 4.5 csproj 复制/粘贴到 .Net 4.6。 2 项目。然后我必须记住避免在那个 .Net 4.6.2 项目上更新我的包,否则它会覆盖我对 PCL 程序集的引用。

我将不胜感激任何帮助。我花了几个小时玩 nuget update 命令,但还没有找到避免 netstandard 的诀窍。我得到的最接近的是在 csproj 中使用“TargetFrameworks”而不是“TargetFrameworkVersion”,但也遇到了麻烦。

最佳答案

When using nuget packages is there a way to avoid netstandard assemblies in favor of PCL?


这是 known issue对于 .net 4.6.2 和 4.7.1,由于 4.7.1 中存在错误,因此需要其中一些系统。* 程序集,当您将一些 nuget 包更新到最新版本时,其中一些可能会拉取较新的 netstandard2 .0 程序集。
如果您不想添加这些 netstandard 程序集,您可以定位到 .net 4.7.1,但它仍然需要其中的 12 个,并且在 .net 4.7.2 上,bin 文件夹将只包含您的 dll 和 pdb。有关更详细的信息,您可以引用以下线程:
net462 referencing netstandard2.0 - can the large number of dlls be avoided?

Actually 4.7.1 will also need a few shims in order to be able to load .netstandard2.0 assemblies, but there are only 12 needed and with the tooling that we are about to release these are the only ones that will be copied to the bin folder. On 4.7.2, compatibility with netstandard will be inbox which means that if you retarget your app for 4.7.2 (once that is avaliable) the bin folder will only contain your dlls and pdbs.

In 4.6.2 you still need the shims there because that is the way your netstandard library will be able to bind to the desktop runtime.


.NET Standard issues on .NET Framework 4.7.1
希望这可以帮助。

关于visual-studio-2017 - 使用 nuget 包时,有没有办法避免使用 netstandard 程序集来支持 PCL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49515295/

相关文章:

android - 将项目从 Eclipse ADT 导入到 Android Studio 时,包 com.google.api.client.http.apache 不存在

c# - 使用我的 NuGet 包分发可重用测试类有哪些选项?

c++ - 错误 : LNK1104 cannot open file 'pthread.lib'

c# - 在 Visual Studio 中打开解决方案时如何自动运行 dotnet 命令

javascript - Typescript 生成 typescript 而不是 javascript

java - 演示 java 中的包名称冲突

visual-studio - Visual Studio 2017 状态栏中带有向下箭头的图标 - 这是什么意思?

python - 导入错误 : cannot import name 'IntEnum'

c# - 如何使用 NuGet.Core 创建 NuGet 包?

nuget - 阻止发布到公共(public) NuGet 库