I have an MSBuild task that populates a variable that I would like to use later in the build process (specifically as an argument in a command line build step).
Is there any way to access an MSBuild variable in subsequent build step?
You can use the ##vso[task.setvariable]value logging command from your MSBuild task to pass the variable to VSO like this:
<Message Text="##vso[task.setvariable variable=myvariable;]$(MyMSBuildProperty)" />
You can use the variable in a subsequent build step by using $(myvariable) in the input fields of the command line build task.
Related
We are moving from tfs 2012 to tfs 2018 and converting our XAML build templates to 2015.
For the most part, using the default build template TfvcTemplate12 work well. However when a project references the build number, it fails.
One example is when we use the windows service publish task.
<WindowsServicePublishTask Publish="$(DeployFileService)" ServiceDisplayName="$(ServiceDisplayName)" Destinations="$(ServiceDestinations)" SourcePath="$(OutDir)" BuildNumber="$(BuildNumber)" CreateDropFolder="$(CreateDropFolder)" />
I get the following error
The "WindowsServicePublishTask" task was not given a value for the required parameter "BuildNumber".
How can I reference the build number using TfvcTemplate12?
You are using the wrong environment variables. For XAML build:
TF_BUILD_BUILDNUMBER The build number of the build. For example: CIBuild_20130613.6.
More details please refer TF_BUILD environment variables
You can use the TF_BUILD environment variables to get key bits of data that you need for your build process logic. For example, you can get the path to the source folder or the path to the folder that contains the outputs you want to drop.
TF_BUILD environment variables
Use environment variables in MSBuild
Use environment variables in programs or scripts
Use environment variables in a custom build process
A sample of adding something like the following options to the MSBuild arguments:
/p:DeployOnBuild=true;DeployMethod=Package /p:DefaultPackageOutputDir=”$(TF_BUILD_BINARIESDIRECTORY)”\WebPackage
I finally got a msbuild to execute and do a publish through the command line. Now I'm wondering how do I do that via teamcity?
When I run this command line it works!
C:\TFS\project\myProject\APIproject>msbuild apiproject.csproj
/p:DeployOnBuild=true
/p:PublishProfile="Properties\PublishProfiles\DEV.pubxml"
/p:VisualStudioVersio n=14.0
However, I don't see a good solution in TeamCity to run this script.
See the documentation: add an 'MsBuild' build step and populate the fields appropriately. Your commandline translated to these fields:
'Build file path' relative/path/to/apiproject.csproj
'Targets' I'm guessing 'Build' but can be left empty for the default
'Command line parameters' here you can specify all properties like on the commandline. TeamCity might emit warnings because you do so, because the alternative and preferred way is to make all these properties TeamCity build parameters: TeamCity passes build parameters to MsBuild automatically.
I have an automated build set up in tfs2015 using a web build definition (i.e. not a xaml build definition) and I am looking to pass a custom property to the msbuild command.
I have tried setting a variable in the definition but this is not used in the build process.
the msbuild command argument that I need to pass is /p:myProperty="bob"
The build definition has variables:
yet when I build I get the msbuild command:
C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe "C:\Build\Agent\_work\5ad80936\FullSolution.sln" /nologo /m /nr:false /fl /flp:"logfile=C:\Build\Agent\_work\5ad80936\FullSolution.sln.log" /dl:CentralLogger,"C:\Build\Agent\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\Build\Agent\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:platform="any cpu" /p:configuration="release"
So the BuildConfiguration and BuildPlatform variables are used in the way I would like myProperty to be used, yet this variable is ignored.
I have tried prefixing my variable name with 'Build', but this made no difference.
Can anyone help?
Incidentally, if run the msbuild command locally and append the required argument the build does exactly what I want.
I have found the answer, the variables are simply that, variables. To use those variables as msbuild command line arguments requires the setting of another part of the build definition:
On the build tab set the MSBuild Arguments parameter to use the variable that you have created:
The part in the $() is the variable name used in the TFS build definition, the portion before the = is the name of the property in your msbuild script. These do not necessarily need be the same
I have a custom MSBuild task that implements an output property. How can I retrieve the value of that property on the build server in build workflow activities that occur after the MSBuild activity has completed?
Thanks,
James
Write the property to a file and read it in your build activity. The name of the file should be passed to msbuild on the command line to reduce coupling between team build and msbuild
I need to define some fixed version info in my Build Definition, so I thought about setting the MSBuild Arguments option with this version info. However, I don't know how can I get this arguments values in my MSBuild script.
Is it possible?
You get them the same way you get any other MSBuild arguments. So for example if you set the Workflow Argument to:
MSBuild Arguments: /p:foo=99
From your MSBuild script you access it by doing $(foo)