-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathPackCommand.cs
More file actions
205 lines (165 loc) · 8.14 KB
/
PackCommand.cs
File metadata and controls
205 lines (165 loc) · 8.14 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NuGet.Commands;
using NuGet.Common;
using NuGet.Packaging.Core;
namespace NuGet.CommandLine
{
using System.Globalization;
using NuGet.Packaging;
using NuGet.Versioning;
[Command(typeof(NuGetCommand), "pack", "PackageCommandDescription", MaxArgs = 1, UsageSummaryResourceName = "PackageCommandUsageSummary",
UsageDescriptionResourceName = "PackageCommandUsageDescription", UsageExampleResourceName = "PackCommandUsageExamples")]
public class PackCommand : Command
{
internal static readonly string SymbolsExtension = ".symbols" + PackagingCoreConstants.NupkgExtension;
private readonly HashSet<string> _excludes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, string> _properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private Version _minClientVersionValue;
[Option(typeof(NuGetCommand), "PackageCommandOutputDirDescription")]
public string OutputDirectory { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandBasePathDescription")]
public string BasePath { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandVersionDescription")]
public string Version { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandSuffixDescription")]
public string Suffix { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandExcludeDescription")]
public ICollection<string> Exclude
{
get { return _excludes; }
}
[Option(typeof(NuGetCommand), "PackageCommandSymbolsDescription")]
public bool Symbols { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandToolDescription")]
public bool Tool { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandBuildDescription")]
public bool Build { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandNoDefaultExcludes")]
public bool NoDefaultExcludes { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandNoRunAnalysis")]
public bool NoPackageAnalysis { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandExcludeEmptyDirectories")]
public bool ExcludeEmptyDirectories { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandIncludeReferencedProjects")]
public bool IncludeReferencedProjects { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandPropertiesDescription", AltName = "p")]
public Dictionary<string, string> Properties
{
get
{
return _properties;
}
}
[Option(typeof(NuGetCommand), "PackageCommandMinClientVersion")]
public string MinClientVersion { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandSymbolPackageFormat")]
public string SymbolPackageFormat { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandPackagesDirectory")]
public string PackagesDirectory { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandSolutionDirectory")]
public string SolutionDirectory { get; set; }
[Option(typeof(NuGetCommand), "CommandMSBuildVersion")]
public string MSBuildVersion { get; set; }
[Option(typeof(NuGetCommand), "CommandMSBuildPath")]
public string MSBuildPath { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandInstallPackageToOutputPath")]
public bool InstallPackageToOutputPath { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandOutputFileNamesWithoutVersion")]
public bool OutputFileNamesWithoutVersion { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandConfigFile")]
public new string ConfigFile { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandDeterministic")]
public bool Deterministic { get; set; }
[Option(typeof(NuGetCommand), "PackageCommandDeterministicTimestamp")]
public string DeterministicTimestamp { get; set; }
public override void ExecuteCommand()
{
var packArgs = new PackArgs();
packArgs.Logger = Console;
packArgs.Arguments = Arguments;
packArgs.OutputDirectory = OutputDirectory;
packArgs.BasePath = BasePath;
packArgs.MsBuildDirectory = new Lazy<string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(MSBuildPath, MSBuildVersion, Console).Value.Path);
packArgs.Deterministic = Deterministic;
packArgs.DeterministicTimestamp = DeterministicTimestamp;
if (!string.IsNullOrEmpty(PackagesDirectory))
{
packArgs.PackagesDirectory = Path.GetFullPath(PackagesDirectory);
}
if (!string.IsNullOrEmpty(SolutionDirectory))
{
packArgs.SolutionDirectory = Path.GetFullPath(SolutionDirectory);
}
// Get the input file
packArgs.Path = PackCommandRunner.GetInputFile(packArgs);
// Set the current directory if the files being packed are in a different directory
PackCommandRunner.SetupCurrentDirectory(packArgs);
Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildPackage"), Path.GetFileName(packArgs.Path));
if (!string.IsNullOrEmpty(MinClientVersion))
{
if (!System.Version.TryParse(MinClientVersion, out _minClientVersionValue))
{
throw new CommandException(LocalizedResourceManager.GetString("PackageCommandInvalidMinClientVersion"));
}
}
if (!string.IsNullOrEmpty(SymbolPackageFormat))
{
packArgs.SymbolPackageFormat = PackArgs.GetSymbolPackageFormat(SymbolPackageFormat);
}
packArgs.Build = Build;
packArgs.Exclude = Exclude;
packArgs.ExcludeEmptyDirectories = ExcludeEmptyDirectories;
packArgs.IncludeReferencedProjects = IncludeReferencedProjects;
switch (Verbosity)
{
case Verbosity.Detailed:
{
packArgs.LogLevel = LogLevel.Verbose;
break;
}
case Verbosity.Normal:
{
packArgs.LogLevel = LogLevel.Information;
break;
}
case Verbosity.Quiet:
{
packArgs.LogLevel = LogLevel.Minimal;
break;
}
}
packArgs.MinClientVersion = _minClientVersionValue;
packArgs.NoDefaultExcludes = NoDefaultExcludes;
packArgs.NoPackageAnalysis = NoPackageAnalysis;
if (Properties.Any())
{
packArgs.Properties.AddRange(Properties);
}
packArgs.Suffix = Suffix;
packArgs.Symbols = Symbols;
packArgs.Tool = Tool;
packArgs.InstallPackageToOutputPath = InstallPackageToOutputPath;
packArgs.OutputFileNamesWithoutVersion = OutputFileNamesWithoutVersion;
if (!string.IsNullOrEmpty(Version))
{
NuGetVersion version;
if (!NuGetVersion.TryParse(Version, out version))
{
throw new PackagingException(NuGetLogCode.NU5010, string.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, Version));
}
packArgs.Version = version.ToFullString();
}
var packCommandRunner = new PackCommandRunner(packArgs, ProjectFactory.ProjectCreator);
if (!packCommandRunner.RunPackageBuild())
{
throw new ExitCodeException(1);
}
}
}
}