-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNuGet.cake
62 lines (57 loc) · 2.01 KB
/
NuGet.cake
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
public static class NuGet
{
public static readonly string NuGetExePath = Environment.GetEnvironmentVariable("NUGET_EXE");
public static readonly string ServerUri = Environment.GetEnvironmentVariable("NUGET_BASEURL");
public static readonly string ApiKey = Environment.GetEnvironmentVariable("NUGET_APIKEY");
public static string GetPackagePath(string name)
{
var package = $"{name}.{Build.Version}.nupkg";
return System.IO.Path.Combine(Build.Folders.Publish, package);
}
public static string Execute(string arguments)
{
var process = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = NuGetExePath,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
});
return process.StandardOutput.ReadToEnd().Trim();
}
}
Task("nuget-pack")
.DoesForEach(() => Build.ToBePackedByNuGet, project =>
{
Information($"Creating NuGet package for '{project.Path}' in '{Build.Folders.Publish}'...");
DotNetCorePack(project.Path, new DotNetCorePackSettings
{
Configuration = Build.Configuration,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.SetVersion(Build.Version),
NoBuild = true,
NoRestore = true,
OutputDirectory = Build.Folders.Publish,
Verbosity = DotNetCoreVerbosity.Normal
});
});
Task("nuget-push")
.WithCriteria(!BuildSystem.IsLocalBuild) // Only during CI/CD
.Does(() =>
{
Information($"Checking variables for NuGet push ...");
if (string.IsNullOrWhiteSpace(NuGet.ServerUri))
throw new InvalidOperationException("NuGet artifact server uri environment variable was not found.");
if (string.IsNullOrWhiteSpace(NuGet.ApiKey))
throw new InvalidOperationException("NuGet API key environment variable was not found.");
})
.DoesForEach(() => Build.NuGetPackages, project =>
{
Information($"Pushing NuGet package '{project.Path}' to '{NuGet.ServerUri}' ...");
DotNetCoreNuGetPush(project.Path, new DotNetCoreNuGetPushSettings
{
ApiKey = NuGet.ApiKey,
Source = NuGet.ServerUri
});
});