From 1283c6b310aec79e0f7c85eeb38e0baf80d01e98 Mon Sep 17 00:00:00 2001 From: Vitezslav Popovsky Date: Sun, 8 Dec 2024 01:44:47 +0100 Subject: [PATCH] Introduce `NBGV_UseAssemblyVersionInNativeVersion` msbuild property --- doc/msbuild.md | 1 + src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs | 4 +++- .../build/Nerdbank.GitVersioning.targets | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/msbuild.md b/doc/msbuild.md index 03daab3e..b756b78f 100644 --- a/doc/msbuild.md +++ b/doc/msbuild.md @@ -49,6 +49,7 @@ Property | Default | Description `NBGV_ThisAssemblyNamespace` | (empty) | Sets the namespace to use for the generated `ThisAssembly` class. `NBGV_EmitThisAssemblyClass` | `true` | When `false`, suppresses generation of the `ThisAssembly` class. `NBGV_ThisAssemblyIncludesPackageVersion` | `false` | When `true`, a `NuGetPackageVersion` property is added to the `ThisAssembly` class. +`NBGV_UseAssemblyVersionInNativeVersion` | `true` | When `false`, uses the `AssemblyFileVersion` as a native `PRODUCTVERSION`. ### Custom `ThisAssembly` static fields and constants diff --git a/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs b/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs index 2dd70746..463af62e 100644 --- a/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs +++ b/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs @@ -108,6 +108,8 @@ BLOCK NBGV_VERSION_BLOCK public string TargetFileName { get; set; } + public bool UseAssemblyVersionInNativeVersion { get; set; } = true; + /// public override bool Execute() { @@ -166,7 +168,7 @@ private void CreateDefines() return; } - if (!Version.TryParse(this.AssemblyVersion, out Version productVersion)) + if (!Version.TryParse(this.AssemblyVersion, out Version productVersion) || !this.UseAssemblyVersionInNativeVersion) { productVersion = fileVersion; } diff --git a/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets b/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets index 0fa3bb88..ae5a2144 100644 --- a/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets +++ b/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets @@ -215,6 +215,7 @@ AssemblyLanguage="$(AssemblyLanguage)" AssemblyCodepage="$(AssemblyCodepage)" TargetFileName="$(TargetFileName)" + UseAssemblyVersionInNativeVersion="$(NBGV_UseAssemblyVersionInNativeVersion)" />