Skip to content

Instantly share code, notes, and snippets.

@JamesTryand
Forked from half-ogre/NuGet.targets.xml
Created May 3, 2012 09:47
Show Gist options
  • Save JamesTryand/2584772 to your computer and use it in GitHub Desktop.
Save JamesTryand/2584772 to your computer and use it in GitHub Desktop.
A replacement for the NuGet.targets file that requires nuget.exe be on the path, so you don't have to commit it.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Windows specific commands -->
<PackagesConfig Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<PackagesConfig Condition=" '$(OS)' != 'Windows_NT' ">packages.config</PackagesConfig>
<PackagesDir Condition=" '$(OS)' != 'Windows_NT'">$(SolutionDir)packages</PackagesDir>
<!-- NuGet command -->
<NuGetExePath>nuget.exe</NuGetExePath>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSources>""</PackageSources>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand>
<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Try to execute `nuget help` to see if nuget.exe is available via the PATH -->
<Exec Command="cmd.exe /c nuget help &gt; NUL" IgnoreExitCode="True">
<Output TaskParameter="ExitCode" PropertyName="NuGetExeExitCode"/>
</Exec>
<!-- Raise an error if nuget.exe wasn't available via the PATH -->
<Error Text="Failed to execute nuget.exe; please make sure your PATH environment variable provides a path to nuget.exe." Condition="'$(NuGetExeExitCode)' != '' and '$(NuGetExeExitCode)' > '0'" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment