简体   繁体   中英

Can't build .NET 4.5 in VS2015 after VS2019 install

We have this (quite huge) solution in Visual Studio 2015, that consists of 60 projects of class libraries and a few MVC web projects, all with target framework set to .NET 4.5 (not 4.5.1 or the like, plain 4.5). So we are planning to switch to Visual Studio 2019 soon, and so myself and a few others have it installed to get to grips with it. It turns out that the installation has broken "something", so our huge project can no longer compile.

What I know so far is, that during build the solutions main MVC project, the compiler throws the following warning code "MSB3275" for 8 of the dependent projects. The only thing it seems like they have in common is they all reference Entity Framework 6.2.0. After the warning the main MVC project fails to compile stating all referenced dll's can not be found. This is the warning (project name has been obscured for privacy's sake):

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".

So like it says in the error, an indirect dependency is somehow .NET 4.6 now and not 4.5. If I set the target framework of the project to 4.6 it compiles just fine.

I have tried for two days now to resolve this and I am at my wits end, I have tried almost everything with each projects dependencies but nothing seems to work. I do not know what else information I should provide to help solving this, but if anyone wants to have a go at cracking this, I will try and provide the information necessary.

EDIT - Alternative solution

So after using solution posted in this thread, I figured out an alternative fix (a bit more permanent) which I will post here in case anyone else stumble upon this page. The project in question is one that has survived from the .NET 3.5 days and upgraded over the years. This means there is still some legacy code made by previous developers that has not been removed or refactored properly. Apparently the Microsoft.SqlServer.Types dependency was deprecated years ago in our code base, so why was it a problem all of a sudden? Turns out this was at the very bottom of the main web projects web.config file:

<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>

As you can see there, it references up to version 15, a version that was not present until VS2019 was installed. Hence the problem. This poses two solutions:

1: Setting the maximum version to 14 made the project able to compile.

2: Removing the entry outright since it's a deprecated reference.

So there you have it, hopefully this thread will help anyone else with MSB3275 warning compiler codes.

It looks like you reference assemblies from GAC that were updated when you installed VS2019. In VS2015, open the solution and install the Microsoft.SqlServer.Types nuget package .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM