Skip to content

Commit 8a67663

Browse files
committed
update build, target file and drop support for etabs 21 only from etabs 22 and newers
1 parent dbdbe26 commit 8a67663

3 files changed

Lines changed: 189 additions & 93 deletions

File tree

release-package.ps1

Lines changed: 104 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
param(
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
2838
Set-Location $scriptPath
2939

30-
# Check if we're in the right directory
3140
if (-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 ────────────────────────────────────────────────────────────
3746
if ([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

4958
Write-Host "Building EtabSharp v$Version..." -ForegroundColor Green
5059
Write-Host ""
5160

52-
# Step 1: Clean
61+
# ── Step 1: Clean ──────────────────────────────────────────────────────────────
5362
Write-Host "Step 1: Cleaning previous builds..." -ForegroundColor Yellow
5463
dotnet 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 }
5965
Write-Host "✓ Clean completed" -ForegroundColor Green
6066
Write-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 }
6990
Write-Host "✓ Restore completed" -ForegroundColor Green
7091
Write-Host ""
7192

72-
# Step 3: Run tests (optional)
93+
# ── Step 4: Tests ─────────────────────────────────────────────────────────────
7394
if (-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
89110
dotnet 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 }
94112
Write-Host "✓ Build completed" -ForegroundColor Green
95113
Write-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"
100118
if (-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 }
114129
Write-Host "✓ Package created" -ForegroundColor Green
115130
Write-Host ""
116131

117-
# Find the created package
132+
# Locate the produced package
118133
$packageFile = Get-ChildItem "$outputDir\EtabSharp.$Version.nupkg" -ErrorAction SilentlyContinue
119134
if (-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
129144
Write-Host "================================================" -ForegroundColor Green
130145
Write-Host ""
131146
Write-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
136151
Write-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
140155
dotnet nuget verify $packageFile.FullName
141156
Write-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) ─────────────────────────────────────
144190
if ($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

src/EtabSharp/EtabSharp.csproj

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
54
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -8,7 +7,7 @@
87
<!-- Package Identity -->
98
<Title>EtabSharp</Title>
109
<PackageId>EtabSharp</PackageId>
11-
<Version>0.3.4-beta</Version>
10+
<Version>0.3.5-beta</Version>
1211
<Copyright>Copyright © Thanh Tu 2026</Copyright>
1312
<Authors>Thanh Tu</Authors>
1413

@@ -23,17 +22,23 @@
2322
<RepositoryType>git</RepositoryType>
2423
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2524

26-
<!-- Build setting-->
25+
<!-- Build settings -->
2726
<SignAssembly>True</SignAssembly>
2827
<NoWarn>$(NoWarn);IDE0065;IDE0055;IDE0011;S3881;CS1591;CS1570</NoWarn>
2928

3029
<!-- Package Release Notes -->
3130
<PackageReleaseNotes>
32-
v0.3.4-beta
33-
* Update to support for etabs 23
31+
v0.3.5-beta
32+
* Minimum supported ETABS version is now 22 (ETABSv1.dll API v2.0.0, .NET Standard 2.0)
33+
* Added ETABS 24 and ETABS 23 to auto-detection order in .targets file (newest wins)
34+
* Dropped ETABS 21 support — pre-v22 DLLs are COM-only and incompatible
35+
* Added ExcludeFromSingleFile=true so ETABSv1.dll is never bundled inside
36+
a PublishSingleFile exe (fixes API version mismatch error on hidden instance launch)
37+
* Added EtabSharp_CopyEtabsDllToPublish target so dotnet publish reliably
38+
copies ETABSv1.dll to the publish output folder alongside the exe
39+
40+
3441
</PackageReleaseNotes>
35-
36-
3742
</PropertyGroup>
3843

3944
<!-- =========================
@@ -46,49 +51,57 @@
4651

4752
<!-- =========================
4853
Development-only ETABS Reference
49-
(Only used when building the library itself)
54+
(Only used when building the library itself — not shipped in the package)
55+
Detection order: lib\ folder first (local override), then newest ETABS install.
56+
Minimum: ETABS 22 (.NET Standard 2.0 API, file version 2.0.0+)
5057
========================= -->
5158
<PropertyGroup>
52-
<!-- Detect ETABS installation for development -->
59+
<!-- Local lib\ override (highest priority — useful for CI or offline dev) -->
5360
<EtabsDevPath Condition="Exists('$(MSBuildThisFileDirectory)..\..\lib\ETABSv1.dll')">$(MSBuildThisFileDirectory)..\..\lib\ETABSv1.dll</EtabsDevPath>
61+
62+
<!-- ETABS 24 (64-bit) -->
63+
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files\Computers and Structures\ETABS 24\ETABSv1.dll')">C:\Program Files\Computers and Structures\ETABS 24\ETABSv1.dll</EtabsDevPath>
64+
<!-- ETABS 24 (32-bit) -->
65+
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files (x86)\Computers and Structures\ETABS 24\ETABSv1.dll')">C:\Program Files (x86)\Computers and Structures\ETABS 24\ETABSv1.dll</EtabsDevPath>
66+
67+
<!-- ETABS 23 (64-bit) -->
5468
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files\Computers and Structures\ETABS 23\ETABSv1.dll')">C:\Program Files\Computers and Structures\ETABS 23\ETABSv1.dll</EtabsDevPath>
69+
<!-- ETABS 23 (32-bit) -->
5570
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files (x86)\Computers and Structures\ETABS 23\ETABSv1.dll')">C:\Program Files (x86)\Computers and Structures\ETABS 23\ETABSv1.dll</EtabsDevPath>
71+
72+
<!-- ETABS 22 (64-bit) — minimum supported -->
73+
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files\Computers and Structures\ETABS 22\ETABSv1.dll')">C:\Program Files\Computers and Structures\ETABS 22\ETABSv1.dll</EtabsDevPath>
74+
<!-- ETABS 22 (32-bit) — minimum supported -->
75+
<EtabsDevPath Condition="'$(EtabsDevPath)' == '' AND Exists('C:\Program Files (x86)\Computers and Structures\ETABS 22\ETABSv1.dll')">C:\Program Files (x86)\Computers and Structures\ETABS 22\ETABSv1.dll</EtabsDevPath>
5676
</PropertyGroup>
5777

5878
<ItemGroup Condition="'$(EtabsDevPath)' != ''">
5979
<Reference Include="ETABSv1">
6080
<HintPath>$(EtabsDevPath)</HintPath>
61-
<!--
62-
Private=false because:
63-
1. This is a CLASS LIBRARY - it doesn't need ETABSv1.dll in its output
64-
2. The library doesn't ship with ETABSv1.dll
65-
3. Consuming applications get ETABSv1.dll via the .targets file
81+
<!--
82+
Private=false: this is a class library — ETABSv1.dll is not shipped
83+
with the package. Consuming applications receive it via EtabSharp.targets.
6684
-->
6785
<Private>false</Private>
6886
<EmbedInteropTypes>false</EmbedInteropTypes>
6987
</Reference>
7088
</ItemGroup>
7189

72-
<!-- Show ETABS path during development build -->
90+
<!-- Show ETABS dev path during build -->
7391
<Target Name="ShowEtabsDevPath" BeforeTargets="CoreCompile">
7492
<Message Text="[EtabSharp.csproj] ETABS dev reference: $(EtabsDevPath)" Importance="high" Condition="'$(EtabsDevPath)' != ''" />
75-
<Warning Text="[EtabSharp.csproj] ETABS not found - build may fail. Install ETABS or place ETABSv1.dll in lib\ folder." Condition="'$(EtabsDevPath)' == ''" />
93+
<Warning Text="[EtabSharp.csproj] ETABS not found build may fail. Install ETABS 22+ or place ETABSv1.dll in lib\ folder." Condition="'$(EtabsDevPath)' == ''" />
7694
</Target>
7795

7896
<!-- =========================
7997
Package Content
8098
========================= -->
8199
<ItemGroup>
82-
<!-- Include the .targets file for auto-detection -->
100+
<!-- .targets file runs automatically in consuming projects -->
83101
<None Include="build\EtabSharp.targets" Pack="true" PackagePath="build\EtabSharp.targets" />
84102
<None Include="build\EtabSharp.targets" Pack="true" PackagePath="buildTransitive\EtabSharp.targets" />
85-
86-
<!-- Include README -->
103+
<!-- README -->
87104
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
88-
89105
</ItemGroup>
90106

91-
92-
93-
94107
</Project>

0 commit comments

Comments
 (0)