安装VS2019后,无法在VS2015中构建.NET 4.5

时间:2019-05-16 10:07:16

标签: c# asp.net-mvc visual-studio-2015 .net-4.5 visual-studio-2019

我们在Visual Studio 2015中拥有这个(相当大的)解决方案,该解决方案由60个类库项目和一些MVC Web项目组成,所有这些项目的目标框架都设置为.NET 4.5(不是4.5.1等)。 4.5)。 因此,我们计划很快改用Visual Studio 2019,因此我本人和其他一些人也安装了Visual Studio 2019来掌握它。事实证明,安装程序已损坏“某物”,因此我们庞大的项目无法再编译。

到目前为止,我所知道的是,在构建解决方案主MVC项目期间,编译器针对8个从属项目抛出以下警告代码“ MSB3275”。看起来它们唯一的共同点是它们都引用Entity Framework 6.2.0。警告后,主MVC项目无法编译,说明找不到所有引用的dll。这是警告(出于隐私考虑,项目名称已被遮盖):

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\REDACTED.DataAccess\bin\Release\REDACTED.DataAccess.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\Utility.TextGetterLib\bin\Release\Utility.TextGetterLib.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\Utility.ExportToFileLib\bin\Release\Utility.ExportToFileLib.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\REDACTED.DataManager\bin\Release\REDACTED.DataManager.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\Utility.KendoView\bin\Release\Utility.KendoView.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\Utility.EmailServerLib\bin\Release\Utility.EmailServerLib.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\ExcelExporter\bin\Release\ExcelExporter.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "D:\Projects\Git\REDACTED\Utility.UserHelperLib\bin\Release\Utility.UserHelperLib.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.SqlServer.Types, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" which was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".

所以就像错误中所说的那样,间接依赖是某种程度上的.NET 4.6现在而不是4.5。如果将项目的目标框架设置为4.6,则可以正常编译。

我已经尝试了两天来解决此问题,但我已经不知所措了,我已经尝试了每个项目依赖项的几乎所有内容,但似乎没有任何效果。我不知道我还应该提供什么其他信息来帮助解决此问题,但是如果有人想尝试破解这个问题,我会尽力提供必要的信息。

编辑-替代解决方案

因此,在使用了此线程中发布的解决方案之后,我想出了一个替代修补程序(更具永久性),如果其他人偶然发现此页面,我将在此处发布。 有问题的项目是经过.NET 3.5天生存并经过多年升级的项目。这意味着仍有一些以前的开发人员制作的遗留代码尚未正确删除或重构。显然,Microsoft.SqlServer.Types依赖关系在几年前已在我们的代码库中弃用,那么为什么突然有问题呢? 原来这是在主要Web项目web.config文件的最底部:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.0.0" />
  </dependentAssembly>

如您所见,它最多引用版本15,该版本直到安装VS2019才存在。因此出现了问题。这提出了两种解决方案:

1:将最大版本设置为14使得该项目可以编译。

2:由于该条目已弃用,因此将其彻底删除。

因此,有了它,希望该线程可以通过MSB3275警告编译器代码帮助其他人。

1 个答案:

答案 0 :(得分:3)

似乎您引用了GAC中安装了VS2019时更新的程序集。在VS2015中,打开解决方案并安装Microsoft.SqlServer.Types nuget package