forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResolvePublishAssemblies.cs
67 lines (53 loc) · 2.35 KB
/
ResolvePublishAssemblies.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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.ProjectModel;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Resolves the assemblies to be published for a .NET app.
/// </summary>
public class ResolvePublishAssemblies : TaskBase
{
private readonly List<ITaskItem> _assembliesToPublish = new List<ITaskItem>();
[Required]
public string ProjectPath { get; set; }
[Required]
public string AssetsFilePath { get; set; }
[Required]
public string TargetFramework { get; set; }
public string RuntimeIdentifier { get; set; }
public string PlatformLibraryName { get; set; }
public ITaskItem[] PrivateAssetsPackageReferences { get; set; }
/// <summary>
/// All the assemblies to publish.
/// </summary>
[Output]
public ITaskItem[] AssembliesToPublish
{
get { return _assembliesToPublish.ToArray(); }
}
protected override void ExecuteCore()
{
LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
IEnumerable<string> privateAssetsPackageIds = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences);
IPackageResolver packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath);
ProjectContext projectContext = lockFile.CreateProjectContext(
NuGetUtils.ParseFrameworkName(TargetFramework),
RuntimeIdentifier,
PlatformLibraryName);
IEnumerable<ResolvedFile> resolvedAssemblies =
new PublishAssembliesResolver(packageResolver)
.WithPrivateAssets(privateAssetsPackageIds)
.Resolve(projectContext);
foreach (ResolvedFile resolvedAssembly in resolvedAssemblies)
{
TaskItem item = new TaskItem(resolvedAssembly.SourcePath);
item.SetMetadata("DestinationSubPath", resolvedAssembly.DestinationSubPath);
_assembliesToPublish.Add(item);
}
}
}
}