-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathGetPackOutputItemsTask.cs
More file actions
96 lines (74 loc) · 3.87 KB
/
GetPackOutputItemsTask.cs
File metadata and controls
96 lines (74 loc) · 3.87 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
// 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.Globalization;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Commands;
using NuGet.Common;
using NuGet.Versioning;
namespace NuGet.Build.Tasks.Pack
{
public class GetPackOutputItemsTask : Microsoft.Build.Utilities.Task
{
[Required]
public string PackageId { get; set; }
[Required]
public string PackageVersion { get; set; }
[Required]
public string PackageOutputPath { get; set; }
[Required]
public string NuspecOutputPath { get; set; }
public string NuspecInputFilePath { get; set; }
public string[] NuspecProperties { get; set; }
public bool IncludeSymbols { get; set; }
public bool IncludeSource { get; set; }
public string SymbolPackageFormat { get; set; }
public bool OutputFileNamesWithoutVersion { get; set; }
/// <summary>
/// Output items
/// </summary>
[Output]
public ITaskItem[] OutputPackItems { get; set; }
public override bool Execute()
{
var packageId = PackageId;
var packageVersion = PackageVersion;
if (!string.IsNullOrWhiteSpace(NuspecInputFilePath))
{
var nuspecReader = new NuGet.Packaging.NuspecReader(NuspecInputFilePath);
packageId = nuspecReader.GetId();
packageVersion = nuspecReader.GetVersion().ToNormalizedString();
PackArgs packArgs = new PackArgs() { Version = packageVersion };
PackTaskLogic.SetPackArgsPropertiesFromNuspecProperties(packArgs, MSBuildStringUtility.TrimAndExcludeNullOrEmpty(NuspecProperties), NuspecInputFilePath);
packageVersion = packArgs.Version;
}
NuGetVersion version;
if (!NuGetVersion.TryParse(packageVersion, out version))
{
throw new ArgumentException(string.Format(
CultureInfo.CurrentCulture,
Strings.InvalidPackageVersion,
packageVersion));
}
var symbolPackageFormat = PackArgs.GetSymbolPackageFormat(MSBuildStringUtility.TrimAndGetNullForEmpty(SymbolPackageFormat));
var nupkgFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: true, symbols: false, symbolPackageFormat: symbolPackageFormat, excludeVersion: OutputFileNamesWithoutVersion);
var nuspecFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: false, symbols: false, symbolPackageFormat: symbolPackageFormat, excludeVersion: OutputFileNamesWithoutVersion);
var outputs = new List<ITaskItem>();
outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgFileName)));
outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecFileName)));
if (IncludeSource || IncludeSymbols)
{
var nupkgSymbolsFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: true, symbols: true, symbolPackageFormat: symbolPackageFormat, excludeVersion: OutputFileNamesWithoutVersion);
var nuspecSymbolsFileName = PackCommandRunner.GetOutputFileName(packageId, version, isNupkg: false, symbols: true, symbolPackageFormat: symbolPackageFormat, excludeVersion: OutputFileNamesWithoutVersion);
outputs.Add(new TaskItem(Path.Combine(PackageOutputPath, nupkgSymbolsFileName)));
outputs.Add(new TaskItem(Path.Combine(NuspecOutputPath, nuspecSymbolsFileName)));
}
OutputPackItems = outputs.ToArray();
return true;
}
}
}