【发布时间】:2019-05-16 10:07:15
【问题描述】:
我们在 Visual Studio 2015 中有这个(相当大的)解决方案,它由 60 个类库项目和一些 MVC Web 项目组成,所有目标框架都设置为 .NET 4.5(不是 4.5.1 或类似的,纯4.5)。 所以我们计划很快切换到 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 警告编译器代码。
【问题讨论】:
-
看起来 Microsoft.SqlServer.Types 是针对 4.6 构建的。列出的 dll 依赖于它,但是是针对 4.5 构建的。
-
是的,这很明显:) 但是这个问题是在安装 VS2019 之后出现的。没有涉及代码库更改。
-
看起来您引用了 GAC 的组件,这些组件在您安装 VS2019 时已更新。在VS2015中,安装nuget package
-
看看这个:stackoverflow.com/questions/10906637/… 希望能为您指明正确的方向。
-
好的,我已经把它作为答案发布了
标签: c# asp.net-mvc visual-studio-2015 .net-4.5 visual-studio-2019