Specifically, I am looking to zero pad a number to create a string based label. i.e. build 7 into build 007. You can easily add strings together, but in all my searches on formatting, padding, strings, etc... I have not been able to find any references.
Example of what I am working with.
<PropertyGroup>
<FileParserVersion>File Parser $(Major).$(Minor).$(Build) Build $(Revision)</FileParserVersion>
<VersionComment>Automated build: $(FileParserVersion)</VersionComment>
</PropertyGroup>
This is generated: FILEPARSER_1_0_3_BUILD_7
What is preferred: FILEPARSER_1_0_3_BUILD_007
In 4.0+ you can do it in one line with Property Functions (and on MSDN)
$([System.String]::Format('FILEPARSER_$(Major)_$(Minor)_$(Build)_BUILD_{0:000}', $([MSBuild]::Add($(Revision), 0))))
Unfortunately the bogus "Add" is necessary to trick MSBuild to coerce $(Revision) to a number before it coerces it into the object expected by String.Format. If I don't do that it uses a string, and the padding doesn't work. The coercion inside MSBuild could be a bit smarter here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With