44param (
55 [Parameter (Mandatory = $false )]
66 [string ]$Version = " " ,
7-
7+
88 [Parameter (Mandatory = $false )]
99 [switch ]$SkipTests = $false ,
10-
10+
1111 [Parameter (Mandatory = $false )]
1212 [switch ]$Push = $false ,
13-
13+
14+ [Parameter (Mandatory = $false )]
15+ [string ]$ApiKey = " " ,
16+
17+ # Install the packed .nupkg into a local NuGet source folder so sibling
18+ # projects (e.g. EtabExtension.CLI) can consume it without publishing.
1419 [Parameter (Mandatory = $false )]
15- [string ]$ApiKey = " "
20+ [string ]$LocalSource = " " ,
21+
22+ # Clear the NuGet HTTP and package cache before restoring.
23+ # Always true when -LocalSource is used to prevent stale .targets files.
24+ [Parameter (Mandatory = $false )]
25+ [switch ]$ClearCache = $false
1626)
1727
1828$ErrorActionPreference = " Stop"
@@ -27,75 +37,83 @@ Write-Host ""
2737$scriptPath = Split-Path - Parent $MyInvocation.MyCommand.Path
2838Set-Location $scriptPath
2939
30- # Check if we're in the right directory
3140if (-not (Test-Path " EtabSharp.sln" )) {
32- Write-Host " Error: EtabSharp.sln not found. Please run this script from the solution root." - ForegroundColor Red
41+ Write-Host " Error: EtabSharp.sln not found. Run this script from the solution root." - ForegroundColor Red
3342 exit 1
3443}
3544
36- # Get current version from .csproj if not specified
45+ # ── Resolve version ────────────────────────────────────────────────────────────
3746if ([string ]::IsNullOrEmpty($Version )) {
3847 $csprojPath = " src\EtabSharp\EtabSharp.csproj"
3948 $csprojContent = Get-Content $csprojPath - Raw
4049 if ($csprojContent -match ' <Version>(.*?)</Version>' ) {
4150 $Version = $matches [1 ]
4251 Write-Host " Using version from .csproj: $Version " - ForegroundColor Yellow
4352 } else {
44- Write-Host " Error: Could not find version in .csproj and no version specified " - ForegroundColor Red
53+ Write-Host " Error: Could not find version in .csproj and no -Version supplied. " - ForegroundColor Red
4554 exit 1
4655 }
4756}
4857
4958Write-Host " Building EtabSharp v$Version ..." - ForegroundColor Green
5059Write-Host " "
5160
52- # Step 1: Clean
61+ # ── Step 1: Clean ──────────────────────────────────────────────────────────────
5362Write-Host " Step 1: Cleaning previous builds..." - ForegroundColor Yellow
5463dotnet clean -- configuration Release
55- if ($LASTEXITCODE -ne 0 ) {
56- Write-Host " Clean failed!" - ForegroundColor Red
57- exit 1
58- }
64+ if ($LASTEXITCODE -ne 0 ) { Write-Host " Clean failed!" - ForegroundColor Red; exit 1 }
5965Write-Host " ✓ Clean completed" - ForegroundColor Green
6066Write-Host " "
6167
62- # Step 2: Restore
63- Write-Host " Step 2: Restoring NuGet packages..." - ForegroundColor Yellow
64- dotnet restore
65- if ($LASTEXITCODE -ne 0 ) {
66- Write-Host " Restore failed!" - ForegroundColor Red
67- exit 1
68+ # ── Step 2: Clear NuGet cache (always when using local source) ────────────────
69+ if ($ClearCache -or -not [string ]::IsNullOrEmpty($LocalSource )) {
70+ Write-Host " Step 2: Clearing NuGet caches..." - ForegroundColor Yellow
71+ # Clear the global packages cache so the old .targets file is not reused
72+ $nugetCache = " $env: USERPROFILE \.nuget\packages\etabsharp"
73+ if (Test-Path $nugetCache ) {
74+ Remove-Item $nugetCache - Recurse - Force
75+ Write-Host " ✓ Removed cached EtabSharp packages from: $nugetCache " - ForegroundColor Green
76+ } else {
77+ Write-Host " ℹ No cached EtabSharp packages found." - ForegroundColor Gray
78+ }
79+ Write-Host " ✓ Cache cleared" - ForegroundColor Green
80+ Write-Host " "
81+ } else {
82+ Write-Host " Step 2: Skipping cache clear (pass -ClearCache to force)" - ForegroundColor Gray
83+ Write-Host " "
6884}
85+
86+ # ── Step 3: Restore ───────────────────────────────────────────────────────────
87+ Write-Host " Step 3: Restoring NuGet packages..." - ForegroundColor Yellow
88+ dotnet restore
89+ if ($LASTEXITCODE -ne 0 ) { Write-Host " Restore failed!" - ForegroundColor Red; exit 1 }
6990Write-Host " ✓ Restore completed" - ForegroundColor Green
7091Write-Host " "
7192
72- # Step 3: Run tests (optional)
93+ # ── Step 4: Tests ─────────────────────────────────────────────────────────────
7394if (-not $SkipTests ) {
74- Write-Host " Step 3 : Running tests..." - ForegroundColor Yellow
95+ Write-Host " Step 4 : Running tests..." - ForegroundColor Yellow
7596 dotnet test -- configuration Release -- no- restore
7697 if ($LASTEXITCODE -ne 0 ) {
77- Write-Host " Tests failed! Use -SkipTests to skip testing ." - ForegroundColor Red
98+ Write-Host " Tests failed! Use -SkipTests to skip." - ForegroundColor Red
7899 exit 1
79100 }
80101 Write-Host " ✓ All tests passed" - ForegroundColor Green
81102 Write-Host " "
82103} else {
83- Write-Host " Step 3 : Skipping tests (as requested)" - ForegroundColor Yellow
104+ Write-Host " Step 4 : Skipping tests (as requested)" - ForegroundColor Yellow
84105 Write-Host " "
85106}
86107
87- # Step 4 : Build
88- Write-Host " Step 4 : Building in Release mode..." - ForegroundColor Yellow
108+ # ── Step 5 : Build ─────────────────────────────────────────────────────────────
109+ Write-Host " Step 5 : Building in Release mode..." - ForegroundColor Yellow
89110dotnet build src\EtabSharp\EtabSharp.csproj -- configuration Release -- no- restore
90- if ($LASTEXITCODE -ne 0 ) {
91- Write-Host " Build failed!" - ForegroundColor Red
92- exit 1
93- }
111+ if ($LASTEXITCODE -ne 0 ) { Write-Host " Build failed!" - ForegroundColor Red; exit 1 }
94112Write-Host " ✓ Build completed" - ForegroundColor Green
95113Write-Host " "
96114
97- # Step 5 : Pack
98- Write-Host " Step 5 : Creating NuGet package..." - ForegroundColor Yellow
115+ # ── Step 6 : Pack ──────────────────────────────────────────────────────────────
116+ Write-Host " Step 6 : Creating NuGet package..." - ForegroundColor Yellow
99117$outputDir = " .\artifacts"
100118if (-not (Test-Path $outputDir )) {
101119 New-Item - ItemType Directory - Path $outputDir - Force | Out-Null
@@ -107,17 +125,14 @@ dotnet pack src\EtabSharp\EtabSharp.csproj `
107125 -- output $outputDir `
108126 / p:PackageVersion= $Version
109127
110- if ($LASTEXITCODE -ne 0 ) {
111- Write-Host " Pack failed!" - ForegroundColor Red
112- exit 1
113- }
128+ if ($LASTEXITCODE -ne 0 ) { Write-Host " Pack failed!" - ForegroundColor Red; exit 1 }
114129Write-Host " ✓ Package created" - ForegroundColor Green
115130Write-Host " "
116131
117- # Find the created package
132+ # Locate the produced package
118133$packageFile = Get-ChildItem " $outputDir \EtabSharp.$Version .nupkg" - ErrorAction SilentlyContinue
119134if (-not $packageFile ) {
120- Write-Host " Error: Package file not found at $outputDir \EtabSharp.$Version .nupkg" - ForegroundColor Red
135+ Write-Host " Error: Package not found at $outputDir \EtabSharp.$Version .nupkg" - ForegroundColor Red
121136 exit 1
122137}
123138
@@ -129,59 +144,87 @@ Write-Host "✓ Package Created Successfully!" -ForegroundColor Green
129144Write-Host " ================================================" - ForegroundColor Green
130145Write-Host " "
131146Write-Host " Package Details:" - ForegroundColor Cyan
132- Write-Host " Version: $Version " - ForegroundColor White
133- Write-Host " Location: $ ( $packageFile.FullName ) " - ForegroundColor White
134- Write-Host " Size: $packageSize MB" - ForegroundColor White
135- Write-Host " Supported Frameworks: .NET 8.0, .NET 10.0" - ForegroundColor White
147+ Write-Host " Version: $Version " - ForegroundColor White
148+ Write-Host " Location: $ ( $packageFile.FullName ) " - ForegroundColor White
149+ Write-Host " Size: $packageSize MB" - ForegroundColor White
150+ Write-Host " Frameworks: .NET 8.0, .NET 10.0" - ForegroundColor White
136151Write-Host " "
137152
138- # Step 6 : Verify package contents
139- Write-Host " Step 6 : Verifying package contents..." - ForegroundColor Yellow
153+ # ── Step 7 : Verify ────────────────────────────────────────────────────────────
154+ Write-Host " Step 7 : Verifying package contents..." - ForegroundColor Yellow
140155dotnet nuget verify $packageFile.FullName
141156Write-Host " "
142157
143- # Step 7: Push to NuGet (optional)
158+ # ── Step 8: Copy to local NuGet source (optional) ────────────────────────────
159+ if (-not [string ]::IsNullOrEmpty($LocalSource )) {
160+ Write-Host " Step 8: Installing into local NuGet source..." - ForegroundColor Yellow
161+
162+ if (-not (Test-Path $LocalSource )) {
163+ New-Item - ItemType Directory - Path $LocalSource - Force | Out-Null
164+ Write-Host " Created local source folder: $LocalSource " - ForegroundColor Gray
165+ }
166+
167+ Copy-Item $packageFile.FullName $LocalSource - Force
168+ Write-Host " ✓ Copied to: $LocalSource " - ForegroundColor Green
169+
170+ # Register the source if not already present
171+ $existingSources = dotnet nuget list source 2>&1
172+ if ($existingSources -notmatch [regex ]::Escape($LocalSource )) {
173+ dotnet nuget add source $LocalSource -- name " EtabSharpLocal"
174+ Write-Host " ✓ Registered as NuGet source 'EtabSharpLocal'" - ForegroundColor Green
175+ } else {
176+ Write-Host " ℹ NuGet source already registered." - ForegroundColor Gray
177+ }
178+
179+ Write-Host " "
180+ Write-Host " Next: rebuild sidecar to pick up the new package:" - ForegroundColor Yellow
181+ Write-Host " cd ..\EtabExtension.CLI" - ForegroundColor Cyan
182+ Write-Host " .\build-sidecar.ps1" - ForegroundColor Cyan
183+ Write-Host " "
184+ } else {
185+ Write-Host " Step 8: Skipping local install (pass -LocalSource <path> to install locally)" - ForegroundColor Gray
186+ Write-Host " "
187+ }
188+
189+ # ── Step 9: Push to NuGet.org (optional) ─────────────────────────────────────
144190if ($Push ) {
145191 if ([string ]::IsNullOrEmpty($ApiKey )) {
146- Write-Host " Error: -Push specified but no -ApiKey provided" - ForegroundColor Red
192+ Write-Host " Error: -Push specified but no -ApiKey provided. " - ForegroundColor Red
147193 Write-Host " Usage: .\release-package.ps1 -Push -ApiKey YOUR_API_KEY" - ForegroundColor Yellow
148194 exit 1
149195 }
150-
151- Write-Host " Step 7 : Publishing to NuGet.org..." - ForegroundColor Yellow
196+
197+ Write-Host " Step 9 : Publishing to NuGet.org..." - ForegroundColor Yellow
152198 Write-Host " Package: $ ( $packageFile.Name ) " - ForegroundColor White
153-
199+
154200 $confirm = Read-Host " Are you sure you want to publish to NuGet.org? (yes/no)"
155201 if ($confirm -eq " yes" ) {
156202 dotnet nuget push $packageFile.FullName -- api- key $ApiKey -- source https:// api.nuget.org/ v3/ index.json
157-
158203 if ($LASTEXITCODE -eq 0 ) {
159204 Write-Host " "
160205 Write-Host " ✓ Package published successfully!" - ForegroundColor Green
161- Write-Host " It may take a few minutes to appear on NuGet.org" - ForegroundColor Yellow
206+ Write-Host " It may take a few minutes to appear on NuGet.org. " - ForegroundColor Yellow
162207 } else {
163- Write-Host " "
164208 Write-Host " ✗ Publish failed!" - ForegroundColor Red
165209 exit 1
166210 }
167211 } else {
168- Write-Host " Publish cancelled by user " - ForegroundColor Yellow
212+ Write-Host " Publish cancelled. " - ForegroundColor Yellow
169213 }
170214} else {
171215 Write-Host " ================================================" - ForegroundColor Yellow
172- Write-Host " Next Steps: " - ForegroundColor Yellow
216+ Write-Host " Next Steps" - ForegroundColor Yellow
173217 Write-Host " ================================================" - ForegroundColor Yellow
174- Write-Host " 1. Verify package contents:" - ForegroundColor White
175- Write-Host " dotnet nuget verify `" $ ( $packageFile.FullName ) `" " - ForegroundColor Cyan
176218 Write-Host " "
177- Write-Host " 2. Test package locally:" - ForegroundColor White
178- Write-Host " dotnet nuget add source $outputDir --name LocalPackages " - ForegroundColor Cyan
219+ Write-Host " Test locally (recommended before publishing) :" - ForegroundColor White
220+ Write-Host " .\release-package.ps1 -LocalSource C:\LocalNuGet -ClearCache " - ForegroundColor Cyan
179221 Write-Host " "
180- Write-Host " 3. Publish to NuGet.org:" - ForegroundColor White
181- Write-Host " .\release-package.ps1 -Version $Version -Push -ApiKey YOUR_API_KEY" - ForegroundColor Cyan
222+ Write-Host " Then update EtabExtension.CLI to reference 0.3.5-beta and rebuild:" - ForegroundColor White
223+ Write-Host " cd ..\EtabExtension.CLI" - ForegroundColor Cyan
224+ Write-Host " .\build-sidecar.ps1" - ForegroundColor Cyan
182225 Write-Host " "
183- Write-Host " Or manually :" - ForegroundColor White
184- Write-Host " dotnet nuget push `" $ ( $packageFile .FullName ) `" --api-key YOUR_KEY --source https://api.nuget.org/v3/index.json " - ForegroundColor Cyan
226+ Write-Host " Publish to NuGet.org when ready :" - ForegroundColor White
227+ Write-Host " .\release-package.ps1 -Push -ApiKey YOUR_API_KEY " - ForegroundColor Cyan
185228 Write-Host " "
186229}
187230
0 commit comments