How do I use Team Build Properties in MSBuild? - msbuild

I have a simple tfs-2010 build definition using the default process template. In it I defined the Build Number Format using $(BuildID) to define part of the computed field. This works and I can see what BuildID's value is.
Now I try to pass the BuildID property to MSBuild as an argument:
/p:SomeProperty=$(BuildID)
However when I look at the build log I see SomeProperty literally equals $(BuildID) rather then the value of BuildID.
What am I missing?
Update for clarity: What I'm asking is how to reference as a Build Process Parameter in the Build Definition. For example Build Number Format has a default expression of $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)

You need to use a VB.NET expression. For example:
String.Format("/p:SomeProperty={0}", BuildDetail.BuildNumber)
The Build Number tokens, e.g. $(BuildDefinitionName), are specific to the Build Number Format process parameter. They aren't tokens that you can use anywhere else in the build process. Most are available in the BuildDetail object or from the environment. The Build Id is a bit of a special case, however. It comes from the identity column of the builds table and isn't directly exposed in our public API. You could extract it from the BuildNumber, like this:
BuildDetail.BuildNumber.Substring(BuildDetail.BuildNumber.LastIndexOf('/') + 1)
Note that you would need to do this in the XAML directly rather than putting a VB expression into the build process parameter editor GUI. That's because those values just get passed through as literal strings.

Related

Azure DevOps Access Custom Field From Script

I have a required custom field on any ticket created (Bug, Tasks, PBI).
I have a pipeline that creates tickets automatically, but the values that are used to create these tickets doesn't have a value for my custom field. I want to set this custom field by adding an entry to the pipeline variables, but I don't know the variable name of the custom field.
How can I find the variable name of the custom field so I can access it?
I found out how to determine your custom variable name.
ADO has a bunch of APIs. The following will give you all the details of a specific work type. For my case I needed the "bug" work type.
/*
Api to display work type fields in JSON format
Replace {} with correct values
*/
https://dev.azure.com/{orginization}/{project}/_apis/wit/workitemtypes/{type}/fields?api-version=6.0
The resulting JSON will give you a whole list of variables. Here is what the System Variable and a Custom Variable look like.
The referenceName is the variable name you would use in your scripts, etc.
TL;DR -
Take your field name and remove all spacing and then put Custom. in front of it.
Custom.FieldNameWithNoSpace

TFS 2015 Build Variable Expansion

We have a VNext build definition, on the Variables tab we have added a few custom variables. In one of the variable values we refer to another variable, i.e.
FileDescription = $(Build.DefinitionName)
However it appears that when we reference it in a PowerShell script the FILEDESCRIPTION environment variable exists but the value is not expanded(it contains "$(Build.DefinitionName)" ) and is treated as a string literal.
The documentation appears to suggest that we should be able to refer to it and it will be subsituted at run-time -
https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables
Is there a way to get TFS to automatically expand the variable at runtime?
In vNext build, it seems not expanded the variable everywhere.
For example, in MSBuild-Arguments, /p:OUTPUT="$(FileDescription)" is expanded to /p:OUTPUT="(the name of build definition)" , but in powershell it will only prints "$(Build.DefinitionName)" directly.
Try to use below Workaround: Try to use the corresponding generated environment variables (for example $env:Build.DefinitionName).
$FileDescription = $env:Build.DefinitionName
Note: If you need to change the path, you have to change the PS script instead of a build variable.

How to user user input variables in Build file?

prompted for user entry by I'm new to ant and I was wondering if it would be possible to create a global variable in the build file so that I can use it repeatedly throughout the file itself.
For example, if the command were 'ant a', I would be able to use that value 'a' throughout the build file (for example in a file path i.e C:/test/a).
The reason I want to know how to do this is because there are multiple values like 'a' (lets say all the letters in the alphabet), and instead of copying and pasting the same code 26 times, I would be able to have 1 piece of code that takes different values (depending on what the user enters). In java you are able to have a variable storing the user input, and use that variable throughout the code (same idea here).
I tried searching for this but wasn't sure how to word it.
UPDATE
With the help of some people I managed to solve what I needed.
So I managed to use Input Task to kind of fix my problem. I prompted the user for an entry by using the following command:
Then I can just use the value entered by the user anywhere i want by simply writing ${hold.it}. For example in a file path "C:/go/to/${hold.it}"
Have a look at Ant properties and the property task used to set them. For example, you can define a property named prop1 and pass its value using ant -Dprop1=some_value.
A property is "global" since after defining it, any part of the buildfile can use it.

How to use variable value in live templates in Intellij IDEA?

I want to create live template for setter.
I've created this template
How can I use value of par variable to generate value of var variable? Basically, I want to avoid redundancy here and put name of variable only once and other one will be generated automatically by some algorithm.
UPDATE
I want to clarify a little bit what I want to achieve.
Suppose I want to create setter with name setTime which has parameter time.
public void setTime(long time)
{
// ...
}
I don't want to type "time" twice - capitalized and non-capitalized. I want to type just parameter name so method name will be generated automatically.
UPDATE (Answer)
Turned out that variable order is important. This is final result of what I want
You can use the soutv as an example, notice how it defines a copy of a variable:
It's also possible to define custom expression for live templates via plugins or Groovy code:
How can i add custom expression functions for Live templates in Intellij.

Specifying multiple MergeSection values when using LINK task on MSBuild

Is there anyway to specify more than one MergeSection value for the MSBuild LINK task? (The MergeSection param is the same as the /merge param for link.exe)
http://msdn.microsoft.com/en-us/library/ee862471.aspx
When calling link.exe you can specify more than one /merge value, but that doesn't seem possible with the MergeSection parameter.
So far the only way I can see to make this work is by using the AddtionalOptions param, but I'm hoping there's a better way to implement this parameter.
Thanks
I think you may have to use AdditionalOptions.
In the Link task the MergeSections property is a string value, not an array, so you can only set one string. Link.exe does not seem to allow you to pass multiple pairs in one command line parameter, you must specify a separate MERGE command line parameter for each pair. The Visual Studio property page only allows a single string for the MergeSections property.