Skip to content

Commit 6570bb2

Browse files
committed
Moved the process into just the targets file and removed the props file from the process. Updated the process to work for VB, C# and F#.
1 parent c2b0408 commit 6570bb2

5 files changed

Lines changed: 80 additions & 43 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ InformationalVersion 2.0.0-beta1
6262

6363
## 🛠 How It Works
6464

65-
The .props file runs early to initialize version variables.
66-
67-
The .targets file finalizes the version and writes to the build log.
65+
The .targets file sets the versions, and generates the AssemblyInfo file, and then writes to the build log.
6866

6967
Local builds use BaseVersion; CI builds can override via CLI.
7068

@@ -77,7 +75,7 @@ Local builds use BaseVersion; CI builds can override via CLI.
7775

7876
Each of these variables can be set in your project file, and/or supplied by your automated build process. You can make them work one way in Visual Studio and another in your automated build.
7977

80-
If you are setting versions in your AssemblyInfo file, then you will want to remove those so that the build process will use this process instead.
78+
If you are setting versions in your AssemblyInfo file, then you will want to remove those so that the build process will use this process instead. If they are not removed, you will get compiler errors from your AssemblyInfo file.
8179

8280
### 💡 Example Build Output
8381

@@ -97,6 +95,8 @@ If you are setting versions in your AssemblyInfo file, then you will want to rem
9795

9896
- .NET SDK-style projects (all frameworks)
9997

98+
- Works with C#, VB.NET and F# projects
99+
100100
- Compatible with MSBuild 16.0+
101101

102102
- CI support: Azure DevOps, GitHub Actions, TeamCity, etc.

src/VersioningPackage.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
</metadata>
2020

2121
<files>
22-
<file src=".\build\Versioning.Common.props" target="build\Versioning.Common.props" />
2322
<file src=".\build\Versioning.Common.targets" target="build\Versioning.Common.targets" />
2423
<file src=".\readme.md" target="readme.md" />
2524
<file src="..\LICENSE" target="LICENSE." />

src/build/Versioning.Common.props

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

src/build/Versioning.Common.targets

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

3+
<!-- Ensure BaseVersion is set -->
4+
<PropertyGroup Condition="'$(BaseVersion)' == ''">
5+
<BaseVersion>0.1.0</BaseVersion> <!-- Fallback default -->
6+
</PropertyGroup>
7+
8+
<!-- Set BuildMetadata if not already defined -->
9+
<PropertyGroup Condition="'$(BuildMetadata)' == ''">
10+
<BuildMetadata></BuildMetadata>
11+
</PropertyGroup>
12+
13+
<!-- Set BuildIdentifier if not already defined -->
14+
<PropertyGroup Condition="'$(BuildIdentifier)' == ''">
15+
<BuildIdentifier></BuildIdentifier>
16+
</PropertyGroup>
17+
18+
<!-- Assembly and File version = fixed numeric version -->
19+
<PropertyGroup>
20+
<AssemblyVersion>$(BaseVersion).0</AssemblyVersion>
21+
<FileVersion>$(BaseVersion).0</FileVersion>
22+
</PropertyGroup>
23+
24+
<!-- NuGet version (semver + metadata) -->
25+
<PropertyGroup Condition="'$(BuildMetadata)' != ''">
26+
<Version>$(BaseVersion)-$(BuildMetadata)</Version>
27+
<InformationalVersion Condition="'$(BuildIdentifier)' != ''">$(BaseVersion)-$(BuildMetadata)+$(BuildIdentifier)</InformationalVersion>
28+
<InformationalVersion Condition="'$(BuildIdentifier)' == ''">$(BaseVersion)-$(BuildMetadata)</InformationalVersion>
29+
</PropertyGroup>
30+
31+
<PropertyGroup Condition="'$(BuildMetadata)' == ''">
32+
<Version>$(BaseVersion).0</Version>
33+
<InformationalVersion Condition="'$(BuildIdentifier)' != ''">$(BaseVersion)+$(BuildIdentifier)</InformationalVersion>
34+
<InformationalVersion Condition="'$(BuildIdentifier)' == ''">$(BaseVersion).0</InformationalVersion>
35+
</PropertyGroup>
36+
337
<PropertyGroup>
438
<LogVersionInfo Condition="'$(LogVersionInfo)' == ''">true</LogVersionInfo>
539
</PropertyGroup>
@@ -17,4 +51,45 @@
1751
<Message Importance="High" Text="=====================================================" />
1852
</Target>
1953

54+
<Target Name="GenerateAssemblyInfo" AfterTargets="LogSelectedVersion" BeforeTargets="BeforeCompile">
55+
<PropertyGroup>
56+
<_GeneratedAssemblyInfoFile Condition="'$(Language)' == 'C#'">$(IntermediateOutputPath)Versioning.Common.GeneratedAssemblyInfo.cs</_GeneratedAssemblyInfoFile>
57+
<_GeneratedAssemblyInfoFile Condition="'$(Language)' == 'VB'">$(IntermediateOutputPath)Versioning.Common.GeneratedAssemblyInfo.vb</_GeneratedAssemblyInfoFile>
58+
<_GeneratedAssemblyInfoFile Condition="'$(Language)' == 'F#'">$(IntermediateOutputPath)Versioning.Common.GeneratedAssemblyInfo.fs</_GeneratedAssemblyInfoFile>
59+
</PropertyGroup>
60+
61+
<ItemGroup>
62+
<Compile Include="$(_GeneratedAssemblyInfoFile)" />
63+
</ItemGroup>
64+
65+
<!-- C# Lines -->
66+
<ItemGroup Condition="'$(Language)' == 'C#'">
67+
<_AssemblyInfoLines Include="using System.Reflection;" />
68+
<_AssemblyInfoLines Include="[assembly: AssemblyVersion(&quot;$(AssemblyVersion)&quot;)]" />
69+
<_AssemblyInfoLines Include="[assembly: AssemblyFileVersion(&quot;$(FileVersion)&quot;)]" />
70+
<_AssemblyInfoLines Condition="'$(TargetFramework)' != 'net35'" Include="[assembly: AssemblyInformationalVersion(&quot;$(InformationalVersion)&quot;)]" />
71+
</ItemGroup>
72+
73+
<!-- VB.NET Lines -->
74+
<ItemGroup Condition="'$(Language)' == 'VB'">
75+
<_AssemblyInfoLines Include="Imports System.Reflection" />
76+
<_AssemblyInfoLines Include="&lt;Assembly: AssemblyVersion(&quot;$(AssemblyVersion)&quot;)&gt;" />
77+
<_AssemblyInfoLines Include="&lt;Assembly: AssemblyFileVersion(&quot;$(FileVersion)&quot;)&gt;" />
78+
<_AssemblyInfoLines Condition="'$(TargetFramework)' != 'net35'" Include="&lt;Assembly: AssemblyInformationalVersion(&quot;$(InformationalVersion)&quot;)&gt;" />
79+
</ItemGroup>
80+
81+
<ItemGroup Condition="'$(Language)' == 'F#'">
82+
<_AssemblyInfoLines Include="open System.Reflection" />
83+
<_AssemblyInfoLines Include="[&lt;assembly: AssemblyVersion(&quot;$(AssemblyVersion)&quot;)&gt;]" />
84+
<_AssemblyInfoLines Include="[&lt;assembly: AssemblyFileVersion(&quot;$(FileVersion)&quot;)&gt;]" />
85+
<_AssemblyInfoLines Condition="'$(TargetFramework)' != 'net35'" Include="[&lt;assembly: AssemblyInformationalVersion(&quot;$(InformationalVersion)&quot;)&gt;]" />
86+
<_AssemblyInfoLines Include="do ()" />
87+
</ItemGroup>
88+
89+
<WriteLinesToFile
90+
File="$(_GeneratedAssemblyInfoFile)"
91+
Overwrite="true"
92+
Lines="@(_AssemblyInfoLines)" />
93+
</Target>
94+
2095
</Project>

src/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- Sets `Version`, `AssemblyVersion`, `FileVersion`, and `InformationalVersion`
88
- Supports CI overrides via MSBuild props:
99
- `BaseVersion`, `BuildMetadata`, `BuildIdentifier`
10-
- Auto-imports `.props` and `.targets` files (no manual imports)
10+
- Auto-imports `.targets` files (no manual imports)
1111
- Logs version info during build (optional)
1212

1313
## 📦 Usage

0 commit comments

Comments
 (0)