问题
I want to create a variable named NugetVersionNumber with the value a date format of $(Date:yyyy.MM.dd)$(Rev:.rr) with the revision at the end.
e.g.
2018.8.23.1
How do I set a process variable to construct this format without changing the build.buildnumber variable?
回答1:
It's not able to directly use $(Date:yyyy.MM.dd)$(Rev:.rr)
as a user-defined variables. (Date:yyyyMMdd)
is a token of build number format not a general variable.
The only way to do this is setting your build number with (Date:yyyy.MM.dd)$(Rev:.rr)
format. And then directly use the $(Build.BuildNumber)
variable .
Since you are going to use this as a Nuget Package Version. You could directly check the Use the build number to version package in Nuget Package task.
To use the build number, check the Use build number to version package box and follow the line's instructions (hover over the blue i icon) to set the build version format string. You must set the build version format string to have at least three parts separated by periods to avoid an error in NuGet packaging. The default build version format string is
$(date:yyyyMMdd)$(rev:.r)
, so a simple change is to add a zero at the end and a period between the date and build counter:$(date:yyyyMMdd).$(rev:.r).0
.
回答2:
I managed to get it to work. I realized that tfs 2017 produces a build variable called 'OutputedVersion' when using the task 'version .NET Core assemblies' and with the regex filter extract the date from the build.buildnumber variable.
来源:https://stackoverflow.com/questions/45842392/setting-a-date-and-revision-number-as-variables-in-tfs-2017