-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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 > 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