//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.BuildTasks {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
///
/// Creates a .nupkg archive from a .nuspec file and content files.
///
public class NuGetPack : ToolTask {
///
/// Gets or sets the path to the .nuspec file.
///
[Required]
public ITaskItem NuSpec { get; set; }
///
/// Gets or sets the base directory, the contents of which gets included in the .nupkg archive.
///
public ITaskItem BaseDirectory { get; set; }
///
/// Gets or sets the path to the directory that will contain the generated .nupkg archive.
///
public ITaskItem OutputPackageDirectory { get; set; }
///
/// Gets or sets the semicolon delimited list of properties to supply to the NuGet Pack command to perform token substitution.
///
public string Properties { get; set; }
///
/// Gets or sets a value indicating whether to generate a symbols nuget package.
///
public bool Symbols { get; set; }
///
/// Returns the fully qualified path to the executable file.
///
///
/// The fully qualified path to the executable file.
///
protected override string GenerateFullPathToTool() {
return this.ToolPath;
}
///
/// Gets the name of the executable file to run.
///
/// The name of the executable file to run.
protected override string ToolName {
get { return "NuGet.exe"; }
}
///
/// Runs the exectuable file with the specified task parameters.
///
///
/// true if the task runs successfully; otherwise, false.
///
public override bool Execute() {
if (this.OutputPackageDirectory != null && Path.GetDirectoryName(this.OutputPackageDirectory.ItemSpec).Length > 0) {
Directory.CreateDirectory(Path.GetDirectoryName(this.OutputPackageDirectory.ItemSpec));
}
bool result = base.Execute();
return result;
}
///
/// Returns a string value containing the command line arguments to pass directly to the executable file.
///
///
/// A string value containing the command line arguments to pass directly to the executable file.
///
protected override string GenerateCommandLineCommands() {
var args = new CommandLineBuilder();
args.AppendSwitch("pack");
args.AppendFileNameIfNotNull(this.NuSpec);
args.AppendSwitchIfNotNull("-BasePath ", this.BaseDirectory);
args.AppendSwitchIfNotNull("-OutputDirectory ", this.OutputPackageDirectory);
args.AppendSwitchIfNotNull("-Properties ", this.Properties);
if (this.Symbols) {
args.AppendSwitch("-Symbols");
}
return args.ToString();
}
}
}