Skip to content

Instantly share code, notes, and snippets.

@sayedihashimi
Forked from half-ogre/NuGet.targets.xml
Created March 6, 2012 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayedihashimi/1984836 to your computer and use it in GitHub Desktop.
Save sayedihashimi/1984836 to your computer and use it in GitHub Desktop.
An MSBuild target to add to your project files that will restore packages *if* nuget.exe is available via the PATH environment variable.
<!-- add this target to *each* project file, and modify the BeforeBuild target that's already in the project file (usually commented out) to depend on it -->
<Target Name="RestoreNuGetPackages" Condition="Exists('.\packages.config')" BeforeTargets="Build">
<!-- try to execute `nuget help` to see if it's available from what's in the PATH -->
<Exec Command="cmd.exe /c nuget help &gt; NUL" IgnoreExitCode="True">
<Output TaskParameter="ExitCode" PropertyName="NuGetExitCode"/>
</Exec>
<!-- raise an error if nuget.exe wassn't available from what's in the PATH -->
<Error Text="Failed to execute nuget.exe; please make sure your PATH environment variable provides a path to nuget.exe." Condition="'$(NuGetExitCode)' != '' and '$(NuGetExitCode)' > '0'" />
<!-- restore packages -->
<Exec Command="nuget install .\packages.config -o $(SolutionDir)\packages" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment