Modifying product version in Wix - version-control

I'm trying to bind the file version from my exe file to be used as product version. Following: How can I set the WiX installer version to the current build version?
The problem is that my assembly builds in the format of e.g 2018.0.0.0. The major upgrade requires a version number of max 255, which means that I have to remove the first two numbers from my productVersion variable before setting it to the ProductVersion property. Is there a way to modify the variable through xsl or something else?.
Modifying through a custom action is no alternative since I want the property to be set in the msi file.
Any help in this djungle is appreciated,
<?define productVersion= !(bind.FileVersion.MyExe.Exe) ?>
<Product Id="*"
UpgradeCode="12345678-1234-1234-1234-123456789123"
Name="My Application"
Language ="1033"
Version="$(var.productVersion)"
Manufacturer="My Company" >

If you can't bind/infer from your assembly then you will need to have your build automation pass a wix variable into candle.exe and use that instead of your bind statement.
In a managed code / vsts / tfs environment my typical flow is that the build definition is the source of truth and it increments and sets a buildnumber during the build. A powershell script updates all the AssemblyFileVersion attributes across my AssemblyInfo files based on this and my wixproj (votive/msbuild) does a regex match on this variable to pass it through to candle.

Related

What's the MSBuild flag to store recently compiled build to a specified location?

I want to store build in a specified folder other than the MSBuild default folder. Is there a MSBuild flag to do so? If yes, then what's the flag and how to use that?
You can set -p:OutDir=..\foo\bar to specify an output location.
For some projects there may be an issue (e.g. mixed ASP.NET Core and .NET Framework) with that and OutputPath can be used instead. It's a bit of a mess due to a stuck transition (see https://github.com/dotnet/msbuild/issues/87)

Override nuspec variable from TeamCity

I've already overridden the version number in the nuspec through the build steps in TeamCity (Nuget Pack), but I don't know how to override any specific variable - is it only possible with the Command Line Parameters or is it possible to expand it in some way so that a new parameter is possible in the build step (as is with the version parameter)?
If only through the command line, do any have suggestions? I guess a path is needed as with the Package Parameter, but other than that I'm lost.
I think that Properties field is what you're looking for:
According to the docs, it can contain:
Semicolon or new-line separated list of package creation properties.
For example, to make a release build, you define here
Configuration=Release.
I've highlighted the term package creation properties as this is the out-of-the-box mechanism to pass parameters to the NuGet package creation process.

Is it possible to Rename or give a custom name to a Build in VSTS?

Is it possible to Rename or give a custom name to a Build in VSTS?
What I want to do is have my builds named after the version number. The version number is written in a .version file in the root directory.
The intended name would be: $(MyVersionNumber):$(Rev:rr)
You can update the build number for current build through Logging Command (e.g. Write-Host "##vso[build.updatebuildnumber]buildnumber").
Simple workflow of your code:
Include $(rev:.r) in default build number format (Options), for example: $(date:yyyyMMdd)-$(rev:.r)
Get current build number from pre-defined variable (Build.BuildNumber/BUILD_BUILDNUMBER)
Get the rev value from this build number in your code
Read version number from .version file
Update build number through Logging Command
Under your build definition you can customize the build name (Build number format):
For example, I added the date variable $(Date:dd.MM.yyyy) with a specific format to the field Build number format:
Microsoft Docs, reference article

TFS: Access a local variable used in build template in a powershell script

i have customized my build template to increment the assemblies version number.
I need a local variable i created/use during the build in a powershell script that is run after the build.
The local variable i created in the build template is called VersionNumber of type string. I would like to use that variable value in a powershell script that is run post build.
How can i do that?
As your question reflect it seems that you are trying to run powershell script soon after your build definition. If that is the case then:
In your build definition you must creating new folder each time the build has been done.
you may use your variable name(which u want to extract) in your folder name(as your variable contains version number).
Then in your powershell script you may sort the folder by datetime and can pick up the folder name (which contains version number) and can use it.
It's also suggested to use your folder name by version number.
As a workaround, you can pass the value as a script parameter to your post-build PowerShell script:
Your script would accept the parameter like so:
# script.ps1
param([string] $MyParam)
# the rest of your script
I also would prefer to be able to access the build template directly. If I learn how, I will post another answer.

How to pass build parameters and other information to powershell script in TFS2013 build?

I am using default build template with TFS 2013, how i can access build parameters (for example, changeset number under build, build directory, source paths, tfs address, agent information...) from powershell script?
Example situation: I want to rewrite all assembly info version informations on Pre-Build script where last part of version number is changeset number, i can probably get changeset with tf.exe commands inside of script but i isn't only thing which i want to know from build agent during build.
I have tried run Get-Variable in script and write it to build but i haven't find any special variables inside of script.
Is there something i have missed or is it so that default build template simply does not pass any variables to powershell runtime during execution?
Figured it out.
Variables are automatically written as environment variables, dir env: showed me that tfs automatically create following variables:
TF_BUILD True
TF_BUILD_BINARIESDIRECTORY C:\WP0\101\bin
TF_BUILD_BUILDDEFINITIONNAME TfsBuildTest2
TF_BUILD_BUILDDIRECTORY C:\WP0\101
TF_BUILD_BUILDNUMBER TfsBuildTest2_20140310.3
TF_BUILD_BUILDREASON Manual
TF_BUILD_BUILDURI vstfs:///Build/Build/6521
TF_BUILD_DROPLOCATION
TF_BUILD_SOURCEGETVERSION C22404
TF_BUILD_SOURCESDIRECTORY C:\WP0\101\src
TF_BUILD_TESTRESULTSDIRECTORY C:\WP0\101\tst
TFS_REG_CRED Build