blob: 1b13ad26ad91000c9f5f8e87b7069cebd9f78f55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
//-----------------------------------------------------------------------
// <copyright file="NuGetPack.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
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;
/// <summary>
/// Creates a .nupkg archive from a .nuspec file and content files.
/// </summary>
public class NuGetPack : ToolTask {
/// <summary>
/// Gets or sets the path to the .nuspec file.
/// </summary>
[Required]
public ITaskItem NuSpec { get; set; }
/// <summary>
/// Gets or sets the base directory, the contents of which gets included in the .nupkg archive.
/// </summary>
public ITaskItem BaseDirectory { get; set; }
/// <summary>
/// Gets or sets the path to the directory that will contain the generated .nupkg archive.
/// </summary>
public ITaskItem OutputPackageDirectory { get; set; }
/// <summary>
/// Gets or sets the semicolon delimited list of properties to supply to the NuGet Pack command to perform token substitution.
/// </summary>
public string Properties { get; set; }
/// <summary>
/// Returns the fully qualified path to the executable file.
/// </summary>
/// <returns>
/// The fully qualified path to the executable file.
/// </returns>
protected override string GenerateFullPathToTool() {
return this.ToolPath;
}
/// <summary>
/// Gets the name of the executable file to run.
/// </summary>
/// <returns>The name of the executable file to run.</returns>
protected override string ToolName {
get { return "NuGet.exe"; }
}
/// <summary>
/// Runs the exectuable file with the specified task parameters.
/// </summary>
/// <returns>
/// true if the task runs successfully; otherwise, false.
/// </returns>
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;
}
/// <summary>
/// Returns a string value containing the command line arguments to pass directly to the executable file.
/// </summary>
/// <returns>
/// A string value containing the command line arguments to pass directly to the executable file.
/// </returns>
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);
return args.ToString();
}
}
}
|