为什么我不能在Visual Studio中合并项目SDK版本?

为什么我不能在Visual Studio中合并项目SDK版本?

问题描述:

首先,我遇到此构建错误,但仅在某些计算机上:

First of all, I'm getting this build error, but only on some machines:


错误CS1705装配'***具有标识
的'***,版本= 1.0.0.0,文化=中性,
PublicKeyToken =空'使用'System.Net.Http,版本= 4.1.1.1,
文化=中性,PublicKeyToken = b03f5f7f11d50a3a',其
版本比引用的程序集'System.Net.Http'高,标识为
'System.Net.Http,版本= 4.1.1.0,Culture = neutral,
PublicKeyToken = b03f5f7f11d50a3a'*** C:\ *** \CSC 1 Active

Error CS1705 Assembly '***' with identity '***, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Net.Http' with identity 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' *** C:\***\CSC 1 Active

我想这是某种程度上的连接使用SDK版本。从属性窗口中可以看到,在某些项目上,我有 Microsoft.NETCore.App 1.1.1 ,而其他项目上有 Microsoft.NETCore.App 1.1 .2

I guess, it's somehow connected with SDK versions. From what I can see in Properties window, on some projects I have Microsoft.NETCore.App 1.1.1 while others have Microsoft.NETCore.App 1.1.2.

软件包更新后,构建成功(但是为什么我被迫更新所有软件包?)。

After package update, build succeeds (but why I am forced to update all packages?).

但是,SDK版本有所不同。现在,我正在尝试使用Visual Studio的此合并功能:

But still, sdk versions differ. And now I'm trying to use this consolidation feature of Visual Studio:

在工具提示中显示:


由于
项目中的其他限制,以下版本不可用packages.config

Following versions are unavaible due to additional constraints in the project or packages.config

如何将所有项目升级到较新的SDK?以及如何确保将来不中断在其他计算机上的构建?

How to upgrade all projects to newer SDK? And how to be sure not to break build on other machines in future?

如果您之前进行了手动升级,则 Microsoft.NETCore.App 包在某些项目上,它们将包含类似< PackageReference Update = Microsoft.NETCore.App Version = 1.1.1的元素 />

If you manually upgraded before, a Microsoft.NETCore.App package on some projects, they will contain an element like <PackageReference Update="Microsoft.NETCore.App" Version="1.1.1" />.

原因是 Microsoft.NET.Sdk SDK将创建一个隐式包引用。

The reason is that the Microsoft.NET.Sdk SDK creates an implicit package reference.

由于隐式引用了包,因此NuGet首先不应该这样做,并且当前的VS更新不再允许隐式更新。

Since the package is implicitly referenced, NuGet should not have done this in the first place and the current VS updates no longer allow to update implicitly referenced packages.

您可以在此处做两件事:

You can do two things here:


  1. 删除所有 PackageReference 元素,用于更改/设置 Microsoft.NET.Sdk 的版本。然后,将让SDK版本(包含在MSBuild / dotnet cli中)选择版本。

  2. 1 +在< PropertyGroup> $中c $ c>您的csproj文件中,设置

  1. Remove all PackageReference elements that change/set the version of Microsoft.NET.Sdk. This will then let the SDK version (included in MSBuild / dotnet cli) choose the version.
  2. 1 + In a <PropertyGroup> of your csproj files, set

 <RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>

这将设置SDK的隐式引用将使用的版本。

This will set the version that the implicit reference of the SDK will use.

1 +在您的csproj文件的< PropertyGroup> 中,设置

1 + In a <PropertyGroup> of your csproj files, set

<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>

然后安装 Microsoft.NETCore.App $的所需版本c $ c>手动

我建议使用选项1,因为它不需要您修改csproj文件更多(例如,添加新项目,重组解决方案等)。

I recommend going with Option 1 since it doesn't require you to modify csproj files any more (e.g. when adding new projects, restructuring solutions etc.).