Skip to content

Commit cb3b3cf

Browse files
committed
Generate assembly metadata during build
Instead of having version number in multiple places, keep it in one place and generate AssemblyInfo.cs on the fly. While on it, add git commit hash to product version and bump version to 2.0.0.0. GitHub: #25 Signed-off-by: Lev Stipakov <[email protected]>
1 parent 9819bbd commit cb3b3cf

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
obj
22
/bin
3+
.vs
4+
.vscode
5+
AssemblyInfo.cs
6+
git_hash.txt

AssemblyInfo.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

OpenVpnService.csproj

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</TargetFrameworkProfile>
1616
<FileAlignment>512</FileAlignment>
1717
<IsWebBootstrapper>false</IsWebBootstrapper>
18-
<ReleaseVersion>1.4.0.1</ReleaseVersion>
18+
<ReleaseVersion>2.0.0.0</ReleaseVersion>
1919
<PublishUrl>publish\</PublishUrl>
2020
<Install>true</Install>
2121
<InstallFrom>Disk</InstallFrom>
@@ -143,4 +143,33 @@
143143
<Target Name="AfterBuild">
144144
</Target>
145145
-->
146-
</Project>
146+
<Target Name="GenerateAssemblyInfo" BeforeTargets="BeforeBuild">
147+
<!-- Run git command and store output in a temporary file -->
148+
<Exec Command="git rev-parse --short HEAD > $(ProjectDir)git_hash.txt 2>nul || echo unknown > $(ProjectDir)git_hash.txt" ContinueOnError="true" />
149+
150+
<!-- Read the Git hash from the file and store it in a property -->
151+
<ReadLinesFromFile File="$(ProjectDir)git_hash.txt">
152+
<Output TaskParameter="Lines" PropertyName="GitHash"/>
153+
</ReadLinesFromFile>
154+
155+
<!-- Default to 'unknown' if Git hash could not be read -->
156+
<PropertyGroup>
157+
<GitHash Condition="'$(GitHash)' == ''">unknown</GitHash>
158+
</PropertyGroup>
159+
160+
<Message Text="Git Commit Hash: $(GitHash)" Importance="high"/>
161+
162+
<!-- Generate AssemblyInfo.cs dynamically -->
163+
<WriteLinesToFile File="AssemblyInfo.cs"
164+
Lines="using System.Reflection%3B
165+
[assembly: AssemblyTitle(&quot;Openvpnserv2&quot;)]
166+
[assembly: AssemblyDescription(&quot;Windows service for running OpenVPN connections in the background&quot;)]
167+
[assembly: AssemblyProduct(&quot;Openvpnserv2&quot;)]
168+
[assembly: AssemblyVersion(&quot;$(ReleaseVersion)&quot;)]
169+
[assembly: AssemblyFileVersion(&quot;$(ReleaseVersion)&quot;)]
170+
[assembly: AssemblyInformationalVersion(&quot;$(ReleaseVersion)+$(GitHash)&quot;)]
171+
[assembly: AssemblyCompany(&quot;The OpenVPN project&quot;)]
172+
[assembly: AssemblyCopyright(&quot;Copyright © OpenVPN project 2025&quot;)]"
173+
Overwrite="true" />
174+
</Target>
175+
</Project>

0 commit comments

Comments
 (0)