Last active
March 9, 2016 17:05
-
-
Save adamzuckerman/056e4ae3482b530493ec to your computer and use it in GitHub Desktop.
Get the NuGet CommandLine executable including path (version 2.8.6)
This file contains 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
<UsingTask | |
TaskName="GetNuGetCommandLine" | |
TaskFactory="CodeTaskFactory" | |
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |
<ParameterGroup> | |
<SolutionPath ParameterType="System.String" Required="true" /> | |
<NuGetCommandLine ParameterType="System.String" Output="true" /> | |
</ParameterGroup> | |
<Task> | |
<Reference Include="System.Xml" /> | |
<Reference Include="System.Xml.Linq"/> | |
<Using Namespace="System.IO" /> | |
<Using Namespace="System.Linq" /> | |
<Using Namespace="System.Xml.Linq" /> | |
<Code Type="Fragment" Language="cs"> | |
<![CDATA[ | |
Log.LogMessage("Getting the NuGet command line.", MessageImportance.High); | |
var solutionDirectory = this.SolutionPath; | |
var nugetDirectory = Path.Combine(solutionDirectory, ".nuget"); | |
if (Directory.Exists(nugetDirectory)) | |
{ | |
var xml = XDocument.Load(Path.Combine(nugetDirectory, "packages.config")); | |
Log.LogMessage("XML: " + xml.Root.Elements("packages").ToString(), MessageImportance.High); | |
var nuget = (from package in xml.Root.Elements("package") | |
where package.Attribute("id").Value.Equals("NuGet.CommandLine", StringComparison.InvariantCultureIgnoreCase) | |
select new | |
{ | |
Id = package.Attribute("id").Value, | |
Version = package.Attribute("version").Value | |
}).FirstOrDefault(); | |
if (nuget != null) | |
{ | |
this.NuGetCommandLine = Path.Combine(solutionDirectory, | |
string.Format("packages\\{0}.{1}\\tools\\NuGet.exe", nuget.Id, nuget.Version)); | |
} | |
} | |
if (string.IsNullOrEmpty(this.NuGetCommandLine)) | |
{ | |
throw new Exception("NuGet.CommandLine package not installed."); | |
} | |
Log.LogMessage("Command Line: " + this.NuGetCommandLine, MessageImportance.High); | |
]]> | |
</Code> | |
</Task> | |
</UsingTask> |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Target Name="Build"> | |
<GetNuGetCommandLine SolutionPath="$(SolutionDir)"> | |
<Output TaskParameter="NuGetCommandLine" PropertyName="NuGetCommandLine" /> | |
</GetNuGetCommandLine> | |
<!-- The version properties ($(Major), $(Minor), $(Build)) are built in a different target. --> | |
<!-- Package the project --> | |
<Exec Command="$(NuGetCommandLine) pack $(TargetName).nuspec -Properties "Configuration=$(ConfigurationName);Version=$(Major).$(Minor).$(Build);ID=$(TargetName)" -OutputDir "$(OutputDirectory)"" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment