0

I have managed to get GitVersion working on my .net project (which updates my AssemblyInfo.cs correctly).

Now I would like to do the same for my AngularJs application. I can see that running GitVersion shows the correct version number, but I would like to update my bower.json file. Does anyone know how I can do this?

r3plica
  • 13,017
  • 23
  • 128
  • 290

1 Answers1

2

What are you using to execute GitVersion? i.e. are you using a script?

GitVersion is not going to update that file for you, but GitVersion will assert the current version number and you can then use something else in your script to update the file.

Personally, almost everything I do in this regard is done using Cake, and there is an addin called MagicChunks, that makes this really easy. For example, this is how I update the package.json file in one of my projects:

https://github.com/gep13/chocolatey-vscode/blob/develop/build.cake#L137-L139

    TransformConfig(projectToPackagePackageJson, projectToPackagePackageJson, new TransformationCollection {
        { "version", parameters.Version.SemVersion }
    });

But you could equally do something similar in say PowerShell, or bash, or whatever you are using to run the build.

UPDATE:

To do something like this directly in PowerShell, you would need something like this (note, this hasn't been tested):

$gitVersionExe = "./../<Path to where GitVersion.exe lives>";
$output = . $gitVersionExe
$joined = $output -join "`n"
$versionInfo = $joined | ConvertFrom-Json
$version = $versionInfo.LegacySemVer

(Get-Content .\bower.json).replace('1.0.0', $version) | Set-Content .\bower,json

NOTE: Here, within the replace statement, I am making an assumption that you want to replace all instances of a made up version number, 1.0.0, within the bower.json file. In practice, you are going to want to fine tune this replacement, so that you are only replacing/changing, exactly the text that you want to change.

NOTE: You can use any property from GitVersion that you would like, I have just used LegacySemVer as an example

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • any idea how I can do this with powershell? – r3plica Feb 15 '19 at 00:33
  • I have updated my answer with some additional information. – Gary Ewan Park Feb 15 '19 at 07:48
  • Thanks, that really helped me out. Out of curiosity, I use grunt as a task manager. Is it possible to use that instead of powershell? – r3plica Feb 15 '19 at 09:57
  • I don't use grunt, so I can't speak to exactly how to do it, but a quick search suggests that yes, it is almost certainly possible: https://stackoverflow.com/questions/27476062/using-grunt-to-replace-text-in-a-file – Gary Ewan Park Feb 15 '19 at 10:00
  • Replacing something in a file, sure. But how do you get the version number? :D – r3plica Feb 15 '19 at 10:13
  • Again, not a grunt user, so don't know for certain, but it would seem to be possible, yes: https://stackoverflow.com/questions/10456865/running-a-command-in-a-grunt-task You would likely need to grab the stdout (which is what is being done above by capturing the output into the $output variable, and from there you will have the asserted information which includes the version number. – Gary Ewan Park Feb 15 '19 at 10:20