-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildnpub.ps1
More file actions
129 lines (110 loc) · 5.3 KB
/
Copy pathbuildnpub.ps1
File metadata and controls
129 lines (110 loc) · 5.3 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# BUILD AND PUBLISH SCRIPT FOR .NET PROJECTS
# - to pack all packages:
# .\buildnpub.ps1 -Pack
# - to pack and push locally:
# .\buildnpub.ps1 -Pack -PushLocal
# - to pack and push to NuGet.org:
# .\buildnpub.ps1 -Pack -PushNuGet
param(
[switch]$Pack,
[switch]$PushLocal,
[switch]$PushNuGet,
[string]$LocalFeed = "C:\Projects\_NuGet",
[string]$NuGetExe = "C:\Exe\nuget.exe"
)
Write-Host "Build & Publish Script" -ForegroundColor Cyan
#region CONFIGURATION - Customize this section for each solution
# ============================================================
# Define projects in dependency order (no dependencies first, then dependents).
# Order determined by analyzing PackageReference elements in Release configuration.
# Projects with no internal dependencies can be in any order relative to each other.
$projectOrder = @(
"Corpus.Core\Corpus.Core.csproj",
"Corpus.Api.Models\Corpus.Api.Models.csproj",
"Corpus.Api.Controllers\Corpus.Api.Controllers.csproj",
"Corpus.Core.Plugin\Corpus.Core.Plugin.csproj",
"Corpus.Sql\Corpus.Sql.csproj",
"Corpus.Sql.PgSql\Corpus.Sql.PgSql.csproj",
"Pythia.Core\Pythia.Core.csproj",
"Pythia.Cli.Core\Pythia.Cli.Core.csproj",
"Pythia.Sql\Pythia.Sql.csproj",
"Pythia.Sql.PgSql\Pythia.Sql.PgSql.csproj",
"Pythia.Core.Plugin\Pythia.Core.Plugin.csproj",
"Pythia.Udp.Plugin\Pythia.Udp.Plugin.csproj",
"Pythia.Xlsx.Plugin\Pythia.Xlsx.Plugin.csproj",
"Pythia.Tagger\Pythia.Tagger.csproj",
"Pythia.Tagger.LiteDB\Pythia.Tagger.LiteDB.csproj",
"Pythia.Tagger.Ita.Plugin\Pythia.Tagger.Ita.Plugin.csproj",
"Pythia.Tools\Pythia.Tools.csproj",
"Pythia.Cli.Plugin.Standard\Pythia.Cli.Plugin.Standard.csproj",
"Pythia.Cli.Plugin.Udp\Pythia.Cli.Plugin.Udp.csproj",
"Pythia.Cli.Plugin.Xlsx\Pythia.Cli.Plugin.Xlsx.csproj",
"Pythia.Api.Models\Pythia.Api.Models.csproj",
"Pythia.Api.Services\Pythia.Api.Services.csproj",
"Pythia.Api.Controllers\Pythia.Api.Controllers.csproj"
)
#endregion
#region REUSABLE LOGIC - No changes needed below this line
# ============================================================
if ($Pack) {
Write-Host "`n=== PACKING PROJECTS IN DEPENDENCY ORDER ===" -ForegroundColor Yellow
foreach ($projPath in $projectOrder) {
$fullPath = Join-Path $PSScriptRoot $projPath
if (Test-Path $fullPath) {
$projDir = Split-Path $fullPath
$releaseDir = Join-Path $projDir "bin\Release"
# Remove packages left over from previous runs so old versions
# don't accumulate and get re-pushed alongside the new one.
if (Test-Path $releaseDir) {
Get-ChildItem $releaseDir -Filter *.nupkg -ErrorAction SilentlyContinue | Remove-Item -Force
Get-ChildItem $releaseDir -Filter *.snupkg -ErrorAction SilentlyContinue | Remove-Item -Force
}
Write-Host "`nPacking $projPath" -ForegroundColor Green
dotnet pack $fullPath -c Release
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to pack $projPath" -ForegroundColor Red
exit 1
}
$nupkgs = Get-ChildItem $releaseDir -Filter *.nupkg -ErrorAction SilentlyContinue
# If pushing locally, add the package immediately after packing
if ($PushLocal) {
foreach ($pkg in $nupkgs) {
Write-Host " -> Adding $($pkg.Name) to local feed" -ForegroundColor Cyan
& $NuGetExe add $pkg.FullName -Source $LocalFeed
}
}
# If pushing to NuGet.org, push immediately after packing
if ($PushNuGet) {
foreach ($pkg in $nupkgs) {
Write-Host " -> Pushing $($pkg.Name) to NuGet.org" -ForegroundColor Cyan
& $NuGetExe push $pkg.FullName -Source https://api.nuget.org/v3/index.json -SkipDuplicate
}
}
} else {
Write-Host "WARNING: Project not found: $fullPath" -ForegroundColor Yellow
}
}
}
# 2. Push to local feed (already done incrementally above if -PushLocal was specified with -Pack)
if ($PushLocal -and -not $Pack) {
Write-Host "`n=== PUSHING TO LOCAL FEED ===" -ForegroundColor Yellow
Write-Host "Note: Packages are already added incrementally during packing." -ForegroundColor Cyan
Write-Host "This section only runs if you use -PushLocal without -Pack." -ForegroundColor Cyan
}
# 3. Push to NuGet.org (only runs if -PushNuGet without -Pack)
if ($PushNuGet -and -not $Pack) {
Write-Host "`n=== PUSHING TO NUGET.ORG ===" -ForegroundColor Yellow
Write-Host "Note: Packages are pushed incrementally during packing when using -Pack -PushNuGet." -ForegroundColor Cyan
foreach ($projPath in $projectOrder) {
$fullPath = Join-Path $PSScriptRoot $projPath
if (Test-Path $fullPath) {
$projDir = Split-Path $fullPath
$nupkgs = Get-ChildItem "$projDir\bin\Release" -Filter *.nupkg -ErrorAction SilentlyContinue
foreach ($pkg in $nupkgs) {
Write-Host "Pushing $($pkg.Name) to NuGet.org" -ForegroundColor Green
& $NuGetExe push $pkg.FullName -Source https://api.nuget.org/v3/index.json -SkipDuplicate
}
}
}
}
Write-Host "`nDone." -ForegroundColor Cyan