What is the EnsureNuGetPackageBuildImports target?

Dave New picture Dave New · Feb 28, 2014 · Viewed 10.9k times · Source

In some of my csproj files I have this but some dont:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

What exactly is this and why do I need it? My other projects are restoring their packages just fine without it.

I am using VS2013 and NuGet 2.8.

Answer

Cameron Taggart picture Cameron Taggart · Mar 3, 2014

It ensures that the imported .props and .targets files are indeed imported. NuGet has supported NuGet MSBuild support since 2.5. EnsureNuGetPackageBuildImports code was added in September, but I think it is a 2.8 change. Unfortunately, it looks like a non-backward compatible change. We have some developers on 2.7 who will now need to upgrade to 2.8. I found EnsureNuGetPackageBuildImports in Common/MsBuildProjectUtility.cs on line 11.