/
Publish.ps1
61 lines (48 loc) · 1.89 KB
/
Publish.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
50
51
52
53
54
55
56
57
58
59
60
61
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$binDirectoryPath = ".\DownloaderNET\bin"
if (Test-Path $binDirectoryPath) {
Remove-Item -Path $binDirectoryPath -Recurse -Force
}
$csprojPath = Join-Path -Path $scriptPath -ChildPath "DownloaderNET\DownloaderNET.csproj"
if (Test-Path $csprojPath) {
[xml]$csprojContent = Get-Content -Path $csprojPath
$versionNode = $csprojContent.Project.PropertyGroup.Version
if ($versionNode -and $versionNode -match "1\.0\.(\d+)") {
$newVersionNumber = [int]$matches[1] + 1
$newVersion = "1.0.$newVersionNumber"
$csprojContent.Project.PropertyGroup.Version = $newVersion
$csprojContent.Save($csprojPath)
Write-Output "Updated version to $newVersion."
}
else {
Write-Error "Version format not recognized or not found."
exit
}
}
else {
Write-Error "DownloaderNET.csproj file not found."
exit
}
dotnet publish ".\DownloaderNET" -c Release
if ([string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) {
$apiKey = Read-Host "Enter your NuGet API key"
if (-not [string]::IsNullOrWhiteSpace($apiKey)) {
[Environment]::SetEnvironmentVariable('NUGET_API_KEY', $apiKey, 'User')
$env:NUGET_API_KEY = $apiKey
Write-Host "Env variable NUGET_API_KEY set to $env:NUGET_API_KEY"
} else {
Write-Error "No API key provided. Exiting script."
exit
}
}
Write-Output "Commit the new version number now and press enter to publish to Nuget"
Read-Host
$packageFilePath = Get-ChildItem -Path ".\DownloaderNET\bin\Release" -Filter "*.nupkg" | Select-Object -First 1
if ($packageFilePath -ne $null) {
dotnet nuget push $packageFilePath.FullName --api-key $env:NUGET_API_KEY --source "https://api.nuget.org/v3/index.json"
}
else {
Write-Error "No .nupkg file found in the publish directory."
exit
}
Write-Output "Package published!"