Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Get BaseVersion.Patch+1 #99

Closed
WalkerCodeRanger opened this issue Oct 9, 2019 · 1 comment
Closed

Can't Get BaseVersion.Patch+1 #99

WalkerCodeRanger opened this issue Oct 9, 2019 · 1 comment

Comments

@WalkerCodeRanger
Copy link

I was really excited at first when I found your project, but due to the limits of constant expressions in C# I'm not able to get it to produce the versions that I need.

Specifically, if the base version is "v2.0.0 then I want "v2.0.1-dev.<commits>." The problem is in the patch number. I basically need ThisAssembly.Git.BaseVersion.Minor + 1. Of course, that can't be done because the minor version is a string and converting between strings and integers isn't possible in constant expressions.

Is there a way I can override the $(GitSemVerPatch) variable to be what I want?

In general, doesn't the limitation to constant expressions really make this approach not work well?

@kzu
Copy link
Member

kzu commented Oct 15, 2019

You can inspect the targets and just place a new MSBuild target (typically in your Directory.Build.targets) in-between those to tweak the versions as you see fit. i.e.:

<Target Name="FixPatch" AfterTargets="GitVersion" BeforeTargets="GitThisAssembly">
  <PropertyGroup>
    <GitSemVerPatch Condition="'$(GitSemVerPatch)' == '0'">1</GitSemVerPatch>
  </PropertyGroup>
</Target>

You can do math or regexes or anything really, just like the targets do to calculate the semver values.
What's important to realize is that all processing is done in build, so by the time the compiler sees the constants, whey are already all pre-calculated. This also means you can use those same values for anything else, not just code (i.e. append the version # to the output file name, such as in an MSI or a VSIX).

@kzu kzu closed this as completed Oct 15, 2019
@devlooped devlooped locked and limited conversation to collaborators Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants