forked from NuGet/NuGet.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackTask.cs
216 lines (202 loc) · 11.5 KB
/
PackTask.cs
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
206
207
208
209
210
211
212
213
214
215
216
// 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.
using System;
using System.Diagnostics;
using Microsoft.Build.Framework;
using NuGet.Commands;
using NuGet.Common;
using NuGet.Packaging;
using ILogger = NuGet.Common.ILogger;
using PackageSpecificWarningProperties = NuGet.Commands.PackCommand.PackageSpecificWarningProperties;
namespace NuGet.Build.Tasks.Pack
{
public class PackTask : Microsoft.Build.Utilities.Task, IPackTaskRequest<ITaskItem>
{
[Required]
public ITaskItem PackItem { get; set; }
public ITaskItem[] PackageFiles { get; set; }
public ITaskItem[] PackageFilesToExclude { get; set; }
public string[] TargetFrameworks { get; set; }
public string[] PackageTypes { get; set; }
public ITaskItem[] BuildOutputInPackage { get; set; }
public ITaskItem[] ProjectReferencesWithVersions { get; set; }
public string PackageId { get; set; }
public string PackageVersion { get; set; }
public string Title { get; set; }
public string[] Authors { get; set; }
public string Description { get; set; }
public bool DevelopmentDependency { get; set; }
public string Copyright { get; set; }
public bool RequireLicenseAcceptance { get; set; }
public string RestoreOutputPath { get; set; }
public string LicenseUrl { get; set; }
public string ProjectUrl { get; set; }
public string IconUrl { get; set; }
public string[] Tags { get; set; }
public string ReleaseNotes { get; set; }
public ITaskItem[] TargetPathsToSymbols { get; set; }
public ITaskItem[] FrameworksWithSuppressedDependencies { get; set; }
public string AssemblyName { get; set; }
public string PackageOutputPath { get; set; }
public bool IsTool { get; set; }
public bool IncludeSymbols { get; set; }
public bool IncludeSource { get; set; }
public bool InstallPackageToOutputPath { get; set; }
public bool OutputFileNamesWithoutVersion { get; set; }
public string RepositoryUrl { get; set; }
public string RepositoryType { get; set; }
public string RepositoryBranch { get; set; }
public string RepositoryCommit { get; set; }
public ITaskItem[] SourceFiles { get; set; }
public bool NoPackageAnalysis { get; set; }
public string NuspecFile { get; set; }
public string SymbolPackageFormat { get; set; }
public string MinClientVersion { get; set; }
public bool Serviceable { get; set; }
public ITaskItem[] FrameworkAssemblyReferences { get; set; }
public bool ContinuePackingAfterGeneratingNuspec { get; set; }
public bool NoDefaultExcludes { get; set; }
public string NuspecOutputPath { get; set; }
public bool IncludeBuildOutput { get; set; }
public string[] BuildOutputFolders { get; set; }
public string[] ContentTargetFolders { get; set; }
public string[] NuspecProperties { get; set; }
public string NuspecBasePath { get; set; }
public string[] AllowedOutputExtensionsInPackageBuildOutputFolder { get; set; }
public string[] AllowedOutputExtensionsInSymbolsPackageBuildOutputFolder { get; set; }
public string NoWarn { get; set; }
public string TreatWarningsAsErrors { get; set; }
public string WarningsAsErrors { get; set; }
public string WarningsNotAsErrors { get; set; }
public string PackageLicenseExpression { get; set; }
public string PackageLicenseFile { get; set; }
public string PackageLicenseExpressionVersion { get; set; }
public string Readme { get; set; }
public bool Deterministic { get; set; }
public string PackageIcon { get; set; }
public ILogger Logger => new MSBuildLogger(Log);
private IPackTaskLogic _packTaskLogic;
/// <summary>
/// This property is only used for testing.
/// </summary>
public IPackTaskLogic PackTaskLogic
{
get
{
if (_packTaskLogic == null)
{
_packTaskLogic = new PackTaskLogic();
}
return _packTaskLogic;
}
set
{
_packTaskLogic = value;
}
}
public override bool Execute()
{
try
{
#if DEBUG
var debugPackTask = Environment.GetEnvironmentVariable("DEBUG_PACK_TASK");
if (!string.IsNullOrEmpty(debugPackTask) && debugPackTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
{
Debugger.Launch();
}
#endif
var request = GetRequest();
var logic = PackTaskLogic;
PackageBuilder packageBuilder = null;
// If packing using a Nuspec file, we don't need to build a PackageBuilder here
// as the package builder is built by reading the manifest file later in the code path.
// Passing a null package builder for nuspec file code path is perfectly valid.
if (string.IsNullOrEmpty(request.NuspecFile))
{
packageBuilder = logic.GetPackageBuilder(request);
}
PackArgs packArgs = logic.GetPackArgs(request);
var packRunner = logic.GetPackCommandRunner(request, packArgs, packageBuilder);
return logic.BuildPackage(packRunner);
}
catch (Exception ex)
{
ExceptionUtilities.LogException(ex, Logger);
return false;
}
}
/// <summary>
/// This method does two important things:
/// 1. Normalizes string parameters, trimming whitespace and coalescing empty strings to null.
/// 2. Wrap <see cref="ITaskItem"/> instances to facility unit testing.
/// </summary>
private IPackTaskRequest<IMSBuildItem> GetRequest()
{
return new PackTaskRequest
{
AllowedOutputExtensionsInPackageBuildOutputFolder = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(AllowedOutputExtensionsInPackageBuildOutputFolder),
AllowedOutputExtensionsInSymbolsPackageBuildOutputFolder = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(AllowedOutputExtensionsInSymbolsPackageBuildOutputFolder),
AssemblyName = MSBuildStringUtility.TrimAndGetNullForEmpty(AssemblyName),
Authors = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(Authors),
BuildOutputInPackage = MSBuildUtility.WrapMSBuildItem(BuildOutputInPackage),
BuildOutputFolders = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(BuildOutputFolders),
ContinuePackingAfterGeneratingNuspec = ContinuePackingAfterGeneratingNuspec,
ContentTargetFolders = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(ContentTargetFolders),
Copyright = MSBuildStringUtility.TrimAndGetNullForEmpty(Copyright),
Description = MSBuildStringUtility.TrimAndGetNullForEmpty(Description),
DevelopmentDependency = DevelopmentDependency,
FrameworkAssemblyReferences = MSBuildUtility.WrapMSBuildItem(FrameworkAssemblyReferences),
FrameworksWithSuppressedDependencies = MSBuildUtility.WrapMSBuildItem(FrameworksWithSuppressedDependencies),
IconUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(IconUrl),
IncludeBuildOutput = IncludeBuildOutput,
IncludeSource = IncludeSource,
IncludeSymbols = IncludeSymbols,
InstallPackageToOutputPath = InstallPackageToOutputPath,
IsTool = IsTool,
LicenseUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(LicenseUrl),
Logger = Logger,
MinClientVersion = MSBuildStringUtility.TrimAndGetNullForEmpty(MinClientVersion),
NoDefaultExcludes = NoDefaultExcludes,
NoPackageAnalysis = NoPackageAnalysis,
NuspecBasePath = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecBasePath),
NuspecFile = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecFile),
NuspecOutputPath = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecOutputPath),
NuspecProperties = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(NuspecProperties),
OutputFileNamesWithoutVersion = OutputFileNamesWithoutVersion,
PackageFiles = MSBuildUtility.WrapMSBuildItem(PackageFiles),
PackageFilesToExclude = MSBuildUtility.WrapMSBuildItem(PackageFilesToExclude),
PackageId = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageId),
PackageOutputPath = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageOutputPath),
PackageTypes = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(PackageTypes),
PackageVersion = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageVersion),
PackItem = MSBuildUtility.WrapMSBuildItem(PackItem),
ProjectReferencesWithVersions = MSBuildUtility.WrapMSBuildItem(ProjectReferencesWithVersions),
ProjectUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(ProjectUrl),
ReleaseNotes = MSBuildStringUtility.TrimAndGetNullForEmpty(ReleaseNotes),
RepositoryType = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryType),
RepositoryUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryUrl),
RepositoryBranch = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryBranch),
RepositoryCommit = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryCommit),
RequireLicenseAcceptance = RequireLicenseAcceptance,
RestoreOutputPath = MSBuildStringUtility.TrimAndGetNullForEmpty(RestoreOutputPath),
Serviceable = Serviceable,
SourceFiles = MSBuildUtility.WrapMSBuildItem(SourceFiles),
SymbolPackageFormat = MSBuildStringUtility.TrimAndGetNullForEmpty(SymbolPackageFormat),
Tags = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(Tags),
TargetFrameworks = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(TargetFrameworks),
TargetPathsToSymbols = MSBuildUtility.WrapMSBuildItem(TargetPathsToSymbols),
Title = MSBuildStringUtility.TrimAndGetNullForEmpty(Title),
TreatWarningsAsErrors = MSBuildStringUtility.TrimAndGetNullForEmpty(TreatWarningsAsErrors),
NoWarn = MSBuildStringUtility.TrimAndGetNullForEmpty(NoWarn),
WarningsAsErrors = MSBuildStringUtility.TrimAndGetNullForEmpty(WarningsAsErrors),
WarningsNotAsErrors = MSBuildStringUtility.TrimAndGetNullForEmpty(WarningsNotAsErrors),
PackageLicenseExpression = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageLicenseExpression),
PackageLicenseFile = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageLicenseFile),
PackageLicenseExpressionVersion = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageLicenseExpressionVersion),
Readme = MSBuildStringUtility.TrimAndGetNullForEmpty(Readme),
Deterministic = Deterministic,
PackageIcon = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageIcon),
};
}
}
}