-
Notifications
You must be signed in to change notification settings - Fork 695
/
PackTask.cs
167 lines (154 loc) · 7.94 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
// 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 Microsoft.Build.Framework;
using NuGet.Commands;
using NuGet.Common;
using NuGet.Packaging;
using ILogger = NuGet.Common.ILogger;
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 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 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 string RepositoryUrl { get; set; }
public string RepositoryType { get; set; }
public ITaskItem[] SourceFiles { get; set; }
public bool NoPackageAnalysis { get; set; }
public string NuspecFile { get; set; }
public string MinClientVersion { get; set; }
public bool Serviceable { get; set; }
public ITaskItem[] AssemblyReferences { get; set; }
public bool ContinuePackingAfterGeneratingNuspec { get; set; }
public string NuspecOutputPath { get; set; }
public bool IncludeBuildOutput { get; set; }
public string BuildOutputFolder { get; set; }
public string[] ContentTargetFolders { get; set; }
public string[] NuspecProperties { get; set; }
public string NuspecBasePath { 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
{
var request = GetRequest();
var logic = PackTaskLogic;
PackageBuilder packageBuilder = null;
var packArgs = logic.GetPackArgs(request);
// 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);
}
var packRunner = logic.GetPackCommandRunner(request, packArgs, packageBuilder);
logic.BuildPackage(packRunner);
return true;
}
catch (Exception ex)
{
ExceptionUtilities.HandleException(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
{
AssemblyName = MSBuildStringUtility.TrimAndGetNullForEmpty(AssemblyName),
AssemblyReferences = MSBuildUtility.WrapMSBuildItem(AssemblyReferences),
Authors = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(Authors),
BuildOutputInPackage = MSBuildUtility.WrapMSBuildItem(BuildOutputInPackage),
BuildOutputFolder = MSBuildStringUtility.TrimAndGetNullForEmpty(BuildOutputFolder),
ContinuePackingAfterGeneratingNuspec = ContinuePackingAfterGeneratingNuspec,
ContentTargetFolders = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(ContentTargetFolders),
Copyright = MSBuildStringUtility.TrimAndGetNullForEmpty(Copyright),
Description = MSBuildStringUtility.TrimAndGetNullForEmpty(Description),
DevelopmentDependency = DevelopmentDependency,
IconUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(IconUrl),
IncludeBuildOutput = IncludeBuildOutput,
IncludeSource = IncludeSource,
IncludeSymbols = IncludeSymbols,
IsTool = IsTool,
LicenseUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(LicenseUrl),
Logger = Logger,
MinClientVersion = MSBuildStringUtility.TrimAndGetNullForEmpty(MinClientVersion),
NoPackageAnalysis = NoPackageAnalysis,
NuspecBasePath = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecBasePath),
NuspecFile = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecFile),
NuspecOutputPath = MSBuildStringUtility.TrimAndGetNullForEmpty(NuspecOutputPath),
NuspecProperties = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(NuspecProperties),
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),
ProjectUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(ProjectUrl),
ReleaseNotes = MSBuildStringUtility.TrimAndGetNullForEmpty(ReleaseNotes),
RepositoryType = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryType),
RepositoryUrl = MSBuildStringUtility.TrimAndGetNullForEmpty(RepositoryUrl),
RequireLicenseAcceptance = RequireLicenseAcceptance,
RestoreOutputPath = MSBuildStringUtility.TrimAndGetNullForEmpty(RestoreOutputPath),
Serviceable = Serviceable,
SourceFiles = MSBuildUtility.WrapMSBuildItem(SourceFiles),
Tags = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(Tags),
TargetFrameworks = MSBuildStringUtility.TrimAndExcludeNullOrEmpty(TargetFrameworks),
TargetPathsToSymbols = MSBuildUtility.WrapMSBuildItem(TargetPathsToSymbols),
Title = MSBuildStringUtility.TrimAndGetNullForEmpty(Title),
};
}
}
}