Skip to content

Commit ca7ec1e

Browse files
committed
Frst release
1 parent 9820606 commit ca7ec1e

File tree

12 files changed

+312
-23
lines changed

12 files changed

+312
-23
lines changed

CreateRelease.ps1

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Class which holds the project entry
2+
class ProjectEntry {
3+
[string]$SolutionFile
4+
[string]$ProjectFile
5+
[string]$PublishProfile
6+
[string]$BinDir
7+
[bool]$CreateRelease
8+
9+
# Default constructor
10+
ProjectEntry() { }
11+
12+
# Constructor
13+
ProjectEntry([string]$rootDir, [string]$solutionFile, [string]$projectFile, [bool]$createRelease) {
14+
$this.SolutionFile = $solutionFile
15+
$this.CreateRelease = $createRelease
16+
# Set the other properties
17+
$this.SetValues($rootDir, $projectFile)
18+
}
19+
20+
# Sets the properties
21+
[void]SetValues([string]$rootDir, [string]$path) {
22+
$this.ProjectFile = Join-Path -Path $rootDir -ChildPath $path
23+
$this.PublishProfile = Join-Path -Path $rootDir -ChildPath "Properties\PublishProfiles\FolderProfile.pubxml"
24+
$this.BinDir = Join-Path -Path $rootDir -ChildPath "bin"
25+
}
26+
}
27+
28+
# Checks if the specified file path is valid
29+
function IsFileValid($filePath) {
30+
# Check if the value is empty or not
31+
if ([string]::IsNullOrEmpty($filePath)) {
32+
return $false;
33+
}
34+
35+
# Get the complete path and check if the file exists
36+
$tmpPath = $filePath
37+
try {
38+
$tmpPath = Resolve-Path -Path $filePath
39+
}
40+
catch {
41+
return $false
42+
}
43+
44+
if ([System.IO.File]::Exists($tmpPath)) {
45+
return $true
46+
}
47+
48+
return $false
49+
}
50+
51+
# Gets the current version number
52+
function GetVersionNumber($filePath) {
53+
$fileValid = IsFileValid $filePath
54+
55+
if (-not $fileValid) {
56+
Write-Host "Can't determine current version number."
57+
return "1.0.0.0"
58+
}
59+
60+
$doc = [XML](Get-Content -Path $filePath)
61+
62+
# Get the specified element
63+
$element = $doc.SelectSingleNode("//AssemblyVersion")
64+
65+
if ($element -eq $null) {
66+
Write-Host "Can't determine current version number. Fallback to 1.0.0.0"
67+
return "1.0.0.0"
68+
}
69+
70+
# Return the version number
71+
return $element.InnerText
72+
}
73+
74+
# Generates a new version number
75+
function GenerateVersionNumber($oldVersion) {
76+
$tmpVersion = [Version]::new()
77+
78+
if (-not [string]::IsNullOrEmpty($oldVersion)) {
79+
try {
80+
$tmpVersion = [Version]::new($oldVersion)
81+
}
82+
catch {
83+
Write-Host "Can't determine old version. Fallback to new version"
84+
}
85+
}
86+
87+
$year = Get-Date -Format "yy"
88+
$dayOfYear = (Get-Date).DayOfYear
89+
$build = 0
90+
$minutesSinceMidnight = [System.Math]::Round((Get-Date).ToUniversalTime().TimeOfDay.TotalMinutes)
91+
92+
Write-Host "Compare old and new version"
93+
if ($year -eq $tmpVersion.Major -and $dayOfYear -eq $tmpVersion.Minor) {
94+
# Add on to the build number if the major and minor versions are equal
95+
$build = $tmpVersion.Build + 1
96+
}
97+
98+
$newVersion = [Version]::new($year, $dayOfYear, $build, $minutesSinceMidnight)
99+
100+
return $newVersion
101+
}
102+
103+
# Changes the value of a specified XML node
104+
function ChangeXmlNode($filePath, $nodeName, $newValue) {
105+
$fileValid = IsFileValid $filePath
106+
107+
if (-not $fileValid) {
108+
Write-Host "ERROR > Can't load file '$filePath'"
109+
return
110+
}
111+
112+
$doc = [XML](Get-Content -Path $filePath)
113+
114+
# Get the specified element
115+
$element = $doc.SelectSingleNode($nodeName)
116+
117+
Write-Host "Node: $nodeName - Old value: $($element.InnerText); New value: $newValue"
118+
119+
# Change the element
120+
$element.InnerText = $newValue
121+
122+
# Save the changes
123+
$doc.Save($filePath)
124+
}
125+
126+
# Changes the version of the project file
127+
function ChangeProjectFile($filePath, $newVersion) {
128+
# Assembly version
129+
ChangeXmlNode $filePath "//AssemblyVersion" $newVersion
130+
131+
# File Version
132+
ChangeXmlNode $filePath "//FileVersion" $newVersion
133+
134+
# Version
135+
ChangeXmlNode $filePath "//Version" $newVersion
136+
}
137+
138+
# Creates a zip archive
139+
function CreateZipArchive($sourceDir, $targetPath) {
140+
Compress-Archive -Path $sourceDir -DestinationPath $targetPath -CompressionLevel Optimal
141+
}
142+
143+
function CreateRelease([ProjectEntry]$project) {
144+
$projectFile = $project.ProjectFile
145+
# Check if the file is valid
146+
$validProjectFile = IsFileValid $project.ProjectFile
147+
148+
if (-not $validProjectFile) {
149+
Write-Host "The project file is not valid."
150+
return 1
151+
}
152+
153+
# ===========================
154+
# Change version number
155+
# Set the complete path
156+
$projectFile = Resolve-Path -Path $projectFile
157+
158+
# Get the old and new version number
159+
$oldVersion = GetVersionNumber $projectFile
160+
$newVersion = GenerateVersionNumber $oldVersion
161+
162+
Write-Host "Change version from $oldVersion to $newVersion"
163+
164+
# Update the files
165+
Write-Host "Update project file"
166+
ChangeProjectFile $projectFile $newVersion
167+
168+
if ($project.CreateRelease -eq $false) {
169+
Write-Host "Skip release creation."
170+
return 0;
171+
}
172+
# ===========================
173+
# Create the release
174+
$dotnet = "C:\Program Files\dotnet\dotnet.exe"
175+
$currentLocation = Get-Location
176+
$output = Join-Path -Path $currentLocation -ChildPath $project.BinDir
177+
178+
# Clear the previous builds
179+
Write-Host "Clear output directory $output"
180+
if ([System.IO.Directory]::Exists($output)) {
181+
Remove-Item "$output\*" -Recurse -Confirm:$false
182+
}
183+
184+
# Create the release
185+
Write-Host "Create release"
186+
$publishProfile = $project.PublishProfile
187+
& $dotnet publish $project.SolutionFile -p:PublishProfile=$publishProfile
188+
189+
return 0
190+
}
191+
192+
# ===========================
193+
# Main entry point
194+
# ===========================
195+
$mainSolution = "MsSql.ClassGenerator.sln"
196+
$core = [ProjectEntry]::new("MsSql.ClassGenerator.Core", $mainSolution, "MsSql.ClassGenerator.Core.csproj", $false)
197+
$desktopApp = [ProjectEntry]::new("MsSql.ClassGenerator", $mainSolution, "MsSql.ClassGenerator.csproj", $true)
198+
$cliApp = [ProjectEntry]::new("MsSql.ClassGenerator.Cli", $mainSolution, "MsSql.ClassGenerator.Cli.csproj", $true)
199+
$projects = @($core, $desktopApp, $cliApp);
200+
201+
Write-Host "Start version update. Files:"
202+
Write-Host " - Project files:"
203+
foreach ($project in $projects) {
204+
Write-Host " > $($project.ProjectFile)"
205+
}
206+
207+
Write-Host "Create releases..."
208+
209+
try {
210+
211+
foreach ($project in $projects) {
212+
213+
$result = CreateRelease $project
214+
215+
if ($result -eq 1) {
216+
Write-Host "An error has occurred while creating the release for $($project.ProjectFile)"
217+
return 1
218+
}
219+
}
220+
221+
return 0
222+
}
223+
catch {
224+
Write-Host "An error has occurred during the process. Error: $_"
225+
return 1
226+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
54
<TargetFramework>net9.0-windows</TargetFramework>
65
<ImplicitUsings>enable</ImplicitUsings>
76
<Nullable>enable</Nullable>
7+
<Version>25.40.0.893</Version>
8+
<FileVersion>25.40.0.893</FileVersion>
9+
<AssemblyVersion>25.40.0.893</AssemblyVersion>
810
</PropertyGroup>
9-
1011
<ItemGroup>
1112
<ProjectReference Include="..\MsSql.ClassGenerator.Core\MsSql.ClassGenerator.Core.csproj" />
1213
</ItemGroup>
13-
14-
</Project>
14+
</Project>

MsSql.ClassGenerator.Core/MsSql.ClassGenerator.Core.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<TargetFramework>net9.0-windows</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<Version>25.40.0.893</Version>
7+
<FileVersion>25.40.0.893</FileVersion>
8+
<AssemblyVersion>25.40.0.893</AssemblyVersion>
79
</PropertyGroup>
8-
910
<ItemGroup>
1011
<PackageReference Include="CommandLineParser" Version="2.9.1" />
1112
<PackageReference Include="Dapper" Version="2.1.66" />
@@ -14,7 +15,6 @@
1415
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
1516
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
1617
</ItemGroup>
17-
1818
<ItemGroup>
1919
<None Update="Files\ClassDefaultWithNs.cgt">
2020
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -44,5 +44,4 @@
4444
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4545
</None>
4646
</ItemGroup>
47-
48-
</Project>
47+
</Project>

MsSql.ClassGenerator/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
1313
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
1414
<!-- Theme setting -->
15-
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/light.cyan.xaml" />
15+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/dark.cyan.xaml" />
1616
</ResourceDictionary.MergedDictionaries>
1717

1818
<Style TargetType="{x:Type mah:MetroHeader}">
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>WinExe</OutputType>
54
<TargetFramework>net9.0-windows</TargetFramework>
65
<Nullable>enable</Nullable>
76
<ImplicitUsings>enable</ImplicitUsings>
87
<UseWPF>true</UseWPF>
8+
<Version>25.40.0.893</Version>
9+
<FileVersion>25.40.0.893</FileVersion>
10+
<AssemblyVersion>25.40.0.893</AssemblyVersion>
11+
<PlatformTarget>x64</PlatformTarget>
12+
<ApplicationIcon>icon.ico</ApplicationIcon>
913
</PropertyGroup>
10-
14+
<ItemGroup>
15+
<Resource Include="icon.ico" />
16+
</ItemGroup>
1117
<ItemGroup>
1218
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
1319
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
1420
<PackageReference Include="MahApps.Metro.IconPacks.ForkAwesome" Version="5.1.0" />
1521
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
1622
</ItemGroup>
17-
1823
<ItemGroup>
1924
<ProjectReference Include="..\MsSql.ClassGenerator.Core\MsSql.ClassGenerator.Core.csproj" />
2025
</ItemGroup>
21-
22-
</Project>
26+
</Project>

MsSql.ClassGenerator/Ui/View/MainWindow.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Width="1200"
1414
Height="800"
1515
mah:DialogParticipation.Register="{Binding}"
16+
Icon="../../icon.ico"
1617
Loaded="MainWindow_OnLoaded"
1718
ResizeMode="CanResizeWithGrip"
1819
TitleCharacterCasing="Normal"
@@ -297,14 +298,14 @@
297298
<view:HeadlineControl
298299
Grid.Row="1"
299300
Grid.Column="0"
300-
HeadlineText="Tables"
301+
HeadlineText="{Binding HeaderTables}"
301302
TextFont="DemiBold"
302303
TextStyle="Italic" />
303304

304305
<view:HeadlineControl
305306
Grid.Row="1"
306307
Grid.Column="1"
307-
HeadlineText="Columns"
308+
HeadlineText="{Binding HeaderColumns}"
308309
TextFont="DemiBold"
309310
TextStyle="Italic" />
310311

@@ -415,9 +416,9 @@
415416
IsEnabled="{Binding IsConnected}"
416417
Orientation="Horizontal">
417418
<Button
418-
Width="75"
419+
Width="170"
419420
Command="{Binding GenerateClassesCommand}"
420-
Content="Create" />
421+
Content="Create classes" />
421422
</StackPanel>
422423
</Grid>
423424
</DockPanel>

0 commit comments

Comments
 (0)