We have a Team City Unit test build which we call using $(teamcity_dotnet_nunitlauncher) through different MSBuild scripts. The build has an environment variable set up. Is there a way we can override the variable through the scripts?
Environment variables are "published" as MSBuild properties, so for example:
$(COMPUTERNAME)
...will give the value of that env var. You can override any property inside an MSBuild script...
<PropertyGroup>
<COMPUTERNAME>NewName</COMPUTERNAME>
</PropertyGroup>
...or pass it in on the command line to MSBuild...
> msbuild My.proj /t:Target /p:COMPUTERNAME=NewName
These two ways to alter the "property" presented by an environment variable are not equal though, when passing a property via the command line, the value will not be overridden if it is declared in an MSBuild file.
Related
I have a Visual Studio 8 2005 project generated by cmake. Is there any way to override some properties (RuntimeLibrary, WarnAsError, WarningLevel) listed in *.vcproj project file at msbuild call in command line?
Unfortunately, this doesn't work:
msbuild my_project.sln /p:Configuration=Debug,WarnAsError=false,RuntimeLibrary=1
In order to set multiple properties, you need to separate them using a semicolon (;), not commas (,). It is also possible to use multiple /p: arguments:
msbuild my_project.sln /p:Prop1=Value2;Prop2=Value2 /p:Prop3=Value3
Now that there isn't a app.config, how do you set gcAllowVeryLargeObjects to true so that you can allocate big arrays?
You can use the corresponding environment variable; just remember to use the COMPlus_ prefix (e.g. COMPlus_gcAllowVeryLargeObjects=1).
You can either set this up from the command line before running dotnet run, or add it on the environment variables section of the project's properties within Visual Studio (or probably add a registry entry).
I have a build definition set up in my TFS 2012 instance. In this Build Definition I want to pass in a custom argument and access said argument in my .csproj file. For example:
MSBuild Arguments: /p:MyFoo=1
In my .csproj file I want to do this:
<ItemGroup Condition=" '$(MyFoo)' == '1' ">
Is this possible, or am I going about this incorrectly?
This is more than possible, it's very easy to do. Edit your build definition, under the process tab expand the "advanced" section and you will see a property called "MSbuild Arguments" add the argument in the format in the question. e.g. /p:MyFoo=1
e.g.
You can also enter the arguments when you queue a build
For example given a project quickie.vcxproj, to build it under c:\output\c without specifying the project name explicitly:
msbuild /t:Rebuild /p:Configuration=Debug /p:PlatformToolset=v100 quickie\quickie.vcxproj /p:OutDir=c:\output\c\$(MSBuildProjectName)\
The result is a directory c:\output\c\$(MSBuildProjectName)
Required result is: c:\output\c\quickie
Attemping with c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild
No. Exceeding thirty characters
Is there a way to use MSBuild syntax to skip a specific target? I have a file consisting of a lot of properties (lines containing /property:X=Y) that I want to pass on to a recursively called instance of MSBuild, but this file also contains a /target:X line, that I do not want to have any effect. I don't have the option to modify the file.
I suppose you are able to edit .proj file. You can manage MSBuild targets executing by the Condition. Your target, which you want to exclude, could contain something like this:
<Target
Name="SomeTarget"
Condition="'$(SomeProperty)'=='true'"
DependsOnTargets="SomeAnotherTarget"/>
SomeProperty can be passed in the calling:
MSBuild.exe build.proj /p:SomeProperty=false
Regards