Wednesday, September 19, 2012

Possible solution to build warning "The primary reference "..." could not be resolved because it has an indirect dependency" after installing .NET 4.5


After installing .NET framework 4.5 I started to experience build errors and warnings when building solutions containing projects targeting .NET 3.5 in Visual Studio 2010.

One of the warnings said:
The primary reference "Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework.

This warning isn’t specific for the primary ref assembly mentioned above, it could be any other assembly it seems. 

After playing around with the .csproj-file trying to take control over MSBuild I discovered this workaround:


  1. In VS, try to identify the referenced assembly or assemblies causing the warning and set the specific version to true in the properties pane.
  2. Unload the project that fails to build in Solution Explorer
  3. Right click the unavailable project and then Edit
  4.  Find the ItemGroup and Reference elements of the concerned assemblies, in this case
<ItemGroup>
  ...
  <Reference Include="Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
    <HintPath>..somepath\Dropit.Extension.dll</HintPath>
  </Reference>

and add the SpecificVersion element

<ItemGroup>
  ...
  <Reference Include="Dropit.Extension, Version=4.1.0.142, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
    <HintPath>..somepath\Dropit.Extension.dll</HintPath>
    <SpecificVersion>True</SpecificVersion>
  </Reference>

6.       Save and build - and it builds!