Share via


Primary reference could not be resolved because it has an indirect dependency on the .NET Framework assembly

Question

Wednesday, April 19, 2017 4:23 PM

I am upgrading to VS2017 from VS2008, but still need to target .net2.0 due to 3rd party contributions to the project.  A referenced project has been changed to target 2.0, and compiled.  The primary project was also changed to target 2.0, but it errors out at build with this:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3258: The primary reference "referenced project" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework."

If I look at the properties page for the mscorlib reference in both the referenceed and primary project, it says it is version 2.0.

However, the detailed build log of the referenced project shows this:

1>Target ResolveAssemblyReferences:
1>  Using "ResolveAssemblyReference" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>  Task "ResolveAssemblyReference"
1>    TargetFrameworkMoniker:
1>        .NETFramework,Version=2.0
1>    TargetFrameworkMonikerDisplayName:
1>        .NETFramework v2.0
1>    TargetedRuntimeVersion:
1>        v4.0.30319

So, that seems to be where the "indirect dependency" is coming in.  The "TargetedRuntimeVersion" does not match the .NETFramework ones.

Anyone know how to fix it?

All replies (4)

Tuesday, April 25, 2017 11:26 AM âś…Answered

The answer probably lies here but I haven't had time to check it yet:

https://msdn.microsoft.com/en-us/library/ff770576.aspx

I'm using the target platform toolset for VIS2017, which is v141.  To target .net 2.0 it says you need to use the Windows7.1SDK platform toolset.  I don't have that option available in the properties page in the VS2017 as yet because it says you need the Microsoft Windows SDK for Windows 7 and .NET Framework 4 SP1 installed:

https://www.microsoft.com/download/details.aspx?id=8279

Seems like this is what would fix the problem.

In any case, we are going to upgrade the 3rd party license to the latest dll release and upgrade everything to .net 4.0 anyway, because the 3rd party license does a lot of new stuff since 2008.


Thursday, April 20, 2017 1:25 AM

In the <PropertyGroup Label="Globals"> section of the vcxproj file, it does list <TargetFrameworkVersion>2.0</TargetFrameworkVersion>.


Thursday, April 20, 2017 7:56 AM

Hi FataL1dea,

Welcome to the MSDN forum.

>>warning MSB3258: The primary reference "referenced project" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework."

Refer to the above error message, it looks like there has an indirect dependency on the assembly which is targeted to the .NET Framework 4.0, and we need to troubleshot this "specific" one.

Please back up your solution, remove all codes from the primary project, then remove the references one by one to build the project to find the supposed indirect reference to .NET 4.0 libs, please have a look at the following similar issues and the marked replies should helpful for you to troubleshot this issue:

Determine the source of an indirect dependency on incorrect .NET Framework version

Program written using .net 4.0 but I need this application to run on computers running .net 2.0

Best regards,

Sara

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Wednesday, April 26, 2017 2:05 AM

Hi FataL1dea,

Thank you for your update and sharing, it will help other community members who meet the same or similar issue.

If you have any other issue about VS IDE in the future, please feel free to let me know.

Best regards,

Sara

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].