C# 安装VS2019后无法在VS2015中生成.NET 4.5

C# 安装VS2019后无法在VS2015中生成.NET 4.5,c#,asp.net-mvc,visual-studio-2015,.net-4.5,visual-studio-2019,C#,Asp.net Mvc,Visual Studio 2015,.net 4.5,Visual Studio 2019,我们在VisualStudio2015中有一个非常庞大的解决方案,它由60个类库项目和几个MVC web项目组成,所有这些项目的目标框架都设置为.NET 4.5,而不是4.5.1或类似版本,即纯4.5。 因此,我们计划很快切换到VisualStudio2019,因此我和其他一些人安装了它来解决这个问题。事实证明,安装破坏了某些东西,因此我们的大型项目无法再编译 到目前为止,我所知道的是,在构建solutions主MVC项目期间,编译器为8个依赖项目抛出以下警告代码MSB3275。看起来它们唯一的

我们在VisualStudio2015中有一个非常庞大的解决方案,它由60个类库项目和几个MVC web项目组成,所有这些项目的目标框架都设置为.NET 4.5,而不是4.5.1或类似版本,即纯4.5。 因此,我们计划很快切换到VisualStudio2019,因此我和其他一些人安装了它来解决这个问题。事实证明,安装破坏了某些东西,因此我们的大型项目无法再编译

到目前为止,我所知道的是,在构建solutions主MVC项目期间,编译器为8个依赖项目抛出以下警告代码MSB3275。看起来它们唯一的共同点是它们都引用实体框架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".
因此,正如它在错误中所说的那样,间接依赖性现在是.NET4.6,而不是4.5。如果我将项目的目标框架设置为4.6,那么它的编译就可以了

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

编辑-替代解决方案

所以在使用了这个帖子中发布的解决方案后,我想出了一个更持久的替代修复方案,我将在这里发布,以防其他人偶然发现这个页面。 所讨论的项目是一个从.NET 3.5天中幸存下来并经过多年升级的项目。这意味着以前的开发人员仍有一些遗留代码没有被正确删除或重构。显然,Microsoft.SqlServer.Types依赖项在我们的代码库中早在几年前就被弃用了,那么为什么它会突然成为一个问题呢? 原来这是在主web projects 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警告编译器代码。

看起来您引用了GAC中安装VS2019时更新的程序集。在VS2015中,打开解决方案并安装。

看起来像Microsoft.SqlServer.Types是根据4.6构建的。列出的DLL依赖于此,但是针对4.5构建的。是的,这一点很明显:但这个问题是在安装VS2019之后出现的。未涉及任何代码基更改。看起来您引用了GAC中安装VS2019时更新的组件。在VS2015中,安装查看:希望能为您指明正确的方向。好的,我已将其作为答案发布感谢您的帮助:我后来还找到了另一种解决方案,我在我的原始帖子中对其进行了编辑,以供其他遇到此问题的人使用。