-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pack.ps1
49 lines (44 loc) · 1.4 KB
/
Pack.ps1
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
param(
[Parameter(Mandatory, Position = 0)]
[string]$ProjectName,
[Parameter(Mandatory, Position = 1)]
[ValidateSet("Major", "Minor", "Patch", "Overwrite", IgnoreCase)]
[string]$VersionUpdate
)
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
throw New-Object -TypeName System.IO.FileNotFoundException -ArgumentList "dotnet executable not found.";
}
$location = Get-Location;
Set-Location $PSScriptRoot;
$VersionUpdate = $VersionUpdate.ToLower();
$projects = [string[]](Get-ChildItem "*/*.csproj" -File -Name);
$project = "$ProjectName.csproj";
if (!$projects.Contains($project)) {
throw New-Object -TypeName System.IO.FileNotFoundException -ArgumentList "$project is not a valid project name.";
}
if ($VersionUpdate -ne 'overwrite') {
$projectFile = [string]((Get-ChildItem "*/$project")[0]);
$project = New-Object xml;
$project.PreserveWhitespace = $true;
$project.Load($projectFile);
$versionNode = $project.SelectSingleNode("/Project/PropertyGroup/Version");
$curVersion = [string]$versionNode.InnerText;
$components = [int[]]($curVersion.Split('.'));
switch ($VersionUpdate) {
'major' {
++$components[0];
$components[1] = $components[2] = 0;
}
'minor' {
++$components[1];
$components[2] = 0;
}
'patch' {
++$components[2];
}
}
$versionNode.InnerText = $components -join '.';
$project.Save($projectFile);
}
dotnet pack $ProjectName -c Release;
Set-Location $location;