Skip to content

Instantly share code, notes, and snippets.

@motowilliams
Forked from half-ogre/NuGet.targets.xml
Created February 22, 2012 04:36
Show Gist options
  • Save motowilliams/1881448 to your computer and use it in GitHub Desktop.
Save motowilliams/1881448 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')">
<!-- 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>
<!-- You might have to un-comment the BeforeBuild target before adding the DependsOnTargets="RestoreNuGetPackages" attribute -->
<Target Name="BeforeBuild" DependsOnTargets="RestoreNuGetPackages"></Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment