-
Notifications
You must be signed in to change notification settings - Fork 22
/
LibrariesTarget.cs
66 lines (58 loc) · 2.58 KB
/
LibrariesTarget.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
// ReSharper disable StringLiteralTypo
// ReSharper disable HeapView.DelegateAllocation
// ReSharper disable HeapView.ClosureAllocation
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable ReturnTypeCanBeEnumerable.Local
// ReSharper disable InvertIf
namespace Build;
using NuGet.Versioning;
internal class LibrariesTarget(
Settings settings,
Commands commands,
Sdk sdk)
: IInitializable, ITarget<IReadOnlyCollection<Library>>
{
public Task InitializeAsync(CancellationToken cancellationToken) => commands.RegisterAsync(
this, "Builds and tests libraries", "libs", "l");
[SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")]
public async Task<IReadOnlyCollection<Library>> RunAsync(CancellationToken cancellationToken)
{
// Libraries
List<Library> libraries =
[
new("Pure.DI.MS",
new Package(GetPackagePath("Pure.DI.MS", settings.NextVersion), false),
sdk.Versions
.Where(i => i.Version.Major >= 7)
.Select(v => $"net{v.Version.Major}.{v.Version.Minor}")
.ToArray(),
["webapi"]),
new("Pure.DI.Abstractions",
new Package(GetPackagePath("Pure.DI.Abstractions", settings.NextVersion), false),
sdk.Versions
.Where(i => i.Version.Major >= 7)
.Select(v => $"net{v.Version.Major}.{v.Version.Minor}")
.ToArray(),
["classlib"])
];
foreach (var library in libraries)
{
await new DotNetPack()
.WithProps(
("configuration", settings.Configuration),
("version", settings.NextVersion.ToString()))
.WithConfiguration(settings.Configuration).WithNoBuild(true).WithNoLogo(true)
.WithProject(Path.Combine(Path.GetFullPath(Path.Combine("src", library.Name)), $"{library.Name}.csproj"))
.WithShortName($"packing {library.Name}")
.BuildAsync(cancellationToken: cancellationToken).EnsureSuccess();
}
return libraries;
}
private string GetPackagePath(string library, NuGetVersion version)
{
var libraryProjectDirectory = Path.GetFullPath(Path.Combine("src", library));
var libraryPackageDir = Path.Combine(libraryProjectDirectory, "bin", settings.Configuration);
var libraryPackageName = $"{library}.{version.ToString()}.nupkg";
return Path.Combine(libraryPackageDir, libraryPackageName);
}
}