Skip to content

Commit 0259bd1

Browse files
committed
Added a script to assist in publishing new builds.
1 parent 6989c62 commit 0259bd1

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

DiskImageTool.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11+
Publish|Any CPU = Publish|Any CPU
1112
Release|Any CPU = Release|Any CPU
1213
EndGlobalSection
1314
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1415
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1516
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
18+
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Publish|Any CPU.Build.0 = Publish|Any CPU
1619
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
1720
{953D9DDF-F8AA-4A81-9DDC-DC43B972FFE7}.Release|Any CPU.Build.0 = Release|Any CPU
1821
EndGlobalSection

DiskImageTool/DiskImageTool.vbproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<TargetCulture>en-US</TargetCulture>
3131
<ProductName>DiskImageTool</ProductName>
3232
<PublisherName>Digitoxin</PublisherName>
33-
<ApplicationRevision>0</ApplicationRevision>
33+
<ApplicationRevision>1</ApplicationRevision>
3434
<ApplicationVersion>2.30.0.%2a</ApplicationVersion>
3535
<UseApplicationTrust>false</UseApplicationTrust>
3636
<PublishWizardCompleted>true</PublishWizardCompleted>
@@ -92,6 +92,16 @@
9292
<PropertyGroup>
9393
<TargetZone>LocalIntranet</TargetZone>
9494
</PropertyGroup>
95+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Publish|AnyCPU'">
96+
<DebugSymbols>false</DebugSymbols>
97+
<DefineTrace>true</DefineTrace>
98+
<OutputPath>bin\Publish\</OutputPath>
99+
<Optimize>true</Optimize>
100+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
101+
<DebugType>none</DebugType>
102+
<PlatformTarget>AnyCPU</PlatformTarget>
103+
<Prefer32Bit>true</Prefer32Bit>
104+
</PropertyGroup>
95105
<ItemGroup>
96106
<Reference Include="CompactJson, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
97107
<HintPath>..\packages\CompactJson.1.2.3\lib\net472\CompactJson.dll</HintPath>
@@ -788,4 +798,7 @@
788798
<Folder Include="Flux\Kryoflux\Forms\" />
789799
</ItemGroup>
790800
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
801+
<PropertyGroup>
802+
<PostBuildEvent>if /I "$(ConfigurationName)"=="Publish" pwsh.exe -NoProfile -ExecutionPolicy Bypass -File "$(MSBuildProjectDirectory)\PostBuildZip.ps1" "$(TargetPath)"</PostBuildEvent>
803+
</PropertyGroup>
791804
</Project>

DiskImageTool/My Project/AssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Imports System.Runtime.InteropServices
3131
' <Assembly: AssemblyVersion("1.0.*")>
3232

3333
<Assembly: AssemblyVersion("1.0.0.0")>
34-
<Assembly: AssemblyFileVersion("2.30.0.0")>
34+
<Assembly: AssemblyFileVersion("2.30.0.1")>

DiskImageTool/PostBuildZip.ps1

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
param(
2+
[string]$ExePath
3+
)
4+
5+
$ErrorActionPreference = 'Stop'
6+
7+
Write-Host "==== Run $(Get-Date -Format 'MM/dd/yyyy HH:mm:ss') ===="
8+
9+
if (-not $ExePath) {
10+
Write-Error "ExePath parameter is required."
11+
exit 1
12+
}
13+
14+
if (-not (Test-Path -LiteralPath $ExePath)) {
15+
Write-Error "ExePath does not exist: $ExePath"
16+
exit 1
17+
}
18+
19+
# Resolve full path and output folder
20+
$ExePath = (Resolve-Path -LiteralPath $ExePath).ProviderPath
21+
$OutputDir = Split-Path -Path $ExePath -Parent # no -LiteralPath here
22+
23+
Write-Host "ExePath = $ExePath"
24+
Write-Host "OutputDir = $OutputDir"
25+
26+
# Read version info from the EXE
27+
$versionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ExePath)
28+
$rawVersion = $versionInfo.FileVersion
29+
30+
Write-Host "Raw version = $rawVersion"
31+
32+
# Try to parse the version string
33+
try {
34+
$parsed = [version]$rawVersion
35+
} catch {
36+
Write-Warning "Could not parse version '$rawVersion'. Falling back to 0.0.1."
37+
$parsed = [version]'0.0.1.0'
38+
}
39+
40+
$major = $parsed.Major
41+
$minor = $parsed.Minor
42+
$revision = $parsed.Revision
43+
if ($revision -lt 0) { $revision = 0 }
44+
45+
Write-Host "Parsed: Major=$major Minor=$minor Revision=$revision"
46+
47+
# Format like 2.30.01 (Major.Minor.Revision(2 digits))
48+
$formattedVersion = '{0}.{1}.{2:00}' -f $major, $minor, $revision
49+
Write-Host "Formatted = $formattedVersion"
50+
51+
# Build zip path based on EXE name
52+
$exeNameNoExt = [System.IO.Path]::GetFileNameWithoutExtension($ExePath)
53+
$zipName = "{0}_{1}.zip" -f $exeNameNoExt, $formattedVersion
54+
$zipPath = Join-Path -Path $OutputDir -ChildPath $zipName
55+
56+
Write-Host "ZipPath = $zipPath"
57+
58+
# Exclusions
59+
$excludeNames = @(
60+
'CompactJson.xml',
61+
'CompactJSON.xml'
62+
)
63+
64+
$excludeExts = @(
65+
'.zip',
66+
'.log'
67+
)
68+
69+
# Collect files to include (publish folder + all subfolders)
70+
$files = Get-ChildItem -Path $OutputDir -Recurse -File |
71+
Where-Object {
72+
($_.Extension -notin $excludeExts) -and
73+
($excludeNames -notcontains $_.Name)
74+
}
75+
76+
$filesCount = $files.Count
77+
Write-Host "Files to zip (after filter): $filesCount"
78+
79+
if ($filesCount -eq 0) {
80+
Write-Warning "No files found to archive after filtering. Aborting."
81+
exit 1
82+
}
83+
84+
# Use .NET's System.IO.Compression instead of Compress-Archive
85+
Add-Type -AssemblyName System.IO.Compression.FileSystem
86+
87+
# Pick maximum compression if available
88+
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
89+
try {
90+
$smallest = [System.IO.Compression.CompressionLevel]::SmallestSize
91+
if ($smallest -ne $null) {
92+
$compressionLevel = $smallest
93+
}
94+
} catch {
95+
# Older frameworks won't have SmallestSize; stay on Optimal
96+
}
97+
98+
# Delete existing zip if present
99+
if (Test-Path -LiteralPath $zipPath) {
100+
Write-Host "Removing existing archive..."
101+
Remove-Item -LiteralPath $zipPath -Force
102+
}
103+
104+
Write-Host "Creating archive via System.IO.Compression with compression level: $compressionLevel"
105+
106+
$zip = $null
107+
$archiveSucceeded = $false
108+
109+
try {
110+
$zip = [System.IO.Compression.ZipFile]::Open(
111+
$zipPath,
112+
[System.IO.Compression.ZipArchiveMode]::Create
113+
)
114+
115+
foreach ($file in $files) {
116+
# relative path inside zip
117+
$relativePath = [System.IO.Path]::GetRelativePath($OutputDir, $file.FullName)
118+
119+
Write-Host " Adding $relativePath"
120+
121+
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
122+
$zip,
123+
$file.FullName,
124+
$relativePath,
125+
$compressionLevel
126+
)
127+
}
128+
129+
$archiveSucceeded = $true
130+
Write-Host "Archive created successfully."
131+
}
132+
catch {
133+
Write-Error "Failed to create archive: $($_.Exception.Message)"
134+
if (Test-Path -LiteralPath $zipPath) {
135+
Write-Host "Removing incomplete archive..."
136+
Remove-Item -LiteralPath $zipPath -Force
137+
}
138+
exit 1
139+
}
140+
finally {
141+
if ($zip -ne $null) {
142+
$zip.Dispose()
143+
}
144+
}

0 commit comments

Comments
 (0)