Wednesday, July 2, 2014

NuGet HintPath Fix/Workaround

So we're using nuget and everything is awesome! We have a solution with projects that are maybe custom extensions or helpers that we will use in all our projects and life will be great! Now we bring those projects into another solution for part of this big project. We keep our concerns separated in separate solutions of course and share some projects that will help keep things cool and aligned. Then we build the solution and WHAT HO! What is this crazy nuget error? So we spend a bunch of time trying to resolve this (how many dev hours worldwide?) We find that the issue lay in the way nuget installs a ref to the packages folder in our projects. The path used is relative to the project. If we don't have them in the other solution's packages folder they don't exist and the build fails. You can resolve this in three ways:

Option 1: Edit the proj files to use $(SolutionDir)/packages/... well this doesn't work when the proj is built from msbuild directly without a solution. But it's pretty good.

Option 2: Build the dependent solution first.

Option 3: Add this to the proj file:
  
	
 <choose>
 <when condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">
  <propertygroup>
   <nugetrepositorypath>..\</nugetrepositorypath>
  </propertygroup> 
 </when>
 <when condition="$(SolutionDir) != '' And $(SolutionDir) != '*Undefined*'">
  <propertygroup>
   <nugetrepositorypath>$(SolutionDir)</nugetrepositorypath>
  </propertygroup> 
 </when>
  </choose>
.
.
.
replace '../' in nuget HintPaths:
<hintpath>$(NuGetRepositoryPath)/packages/...</hintpath>

No comments:

Post a Comment