override project properties on execting msbuild - cmake

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

Related

Pass property value from TFS Build Definition to proj file

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

Is it possible to specify a MSBuild property on the command line which references another property?

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

Why won't MSBuild build a project with a dot in the name?

The Story So Far
I've got a nice solution with a desktop application project, a few library projects, and a couple of development tools projects (also desktop applications). At the moment, my build server outputs all of the code into one OutputPath. So we end up with
drop-x.y.z\
Company.MainApplication.exe <-- main application
Company.MainApplicationCore.dll <-- libraries
Helper.exe <-- developer tools
Grapher.exe
Parser.exe
... <-- the rest of the output
But, we're growing up and people outside of our team want access to our tools. So I want to organize the output. I decided that what we would want is a different OutputPath per executable project
drop-x.y.z\
Company.MainApplication\
Company.MainApplication.exe <-- main application
Company.MainApplicationCore.dll <-- libraries
... <-- application specific output
Helper\
Helper.exe <-- developer tools
... <-- tool specific output
Grapher\
Grapher.exe
...
Parser\
Parser.exe
...
What I Did
I found this simple command. I like it because it retains all the Solution working-dir context that makes msbuild a pain.
msbuild /target:<ProjectName>
For example, from my solution root as a working directory, I would call
PS> msbuild /target:Helper /property:OutputPath="$pwd\out\Helper"
I'm testing this from PowerShell, so that $pwd resolves to the full path to my working directory, or the Solution root in this case. I get the output I desire.
However, when I run this command
PS> msbuild /target:Company.MainApplication /property:OutputPath="$pwd\out\Company.MainApplication"
I get the following error output (there's no more information, I ran with /verbosity:diagnostic)
The target "Company.MainApplication" does not exist in the project.
What I Need
The command fails on any project with a dot or dots in the name. I tried with many combinations of working directories and properties. I tried several ways of escaping the property values. I also tried running the command from a <Task> in a targets file.
I need to know either
A) How to fix this command to work property
B) How to achieve the same output with minimal friction
Try using an underscore as an escape character for the dot in the target parameter, e.g.
msbuild /target:Company_MainApplication /property:OutputPath="$pwd\out\Company.MainApplication"
Specify the target after the -target: switch in the format :. If the project name contains any of the characters %, $, #, ;, ., (, ), or ', replace them with an _ in the specified target name.
https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe?view=vs-2019
Dan Nolan's answer and comments are correct. Just want to supplement the Microsoft documentation.
The /targets: switch is to identify a <Target to run in the project file. You need to supply your .csproj file as a an argument that is not prefixed by a /xx option marker.
You might also want to work based on the .sln file. In that case, you still dont specify the project in the .sln to build in this manner. I'll leave you to search up the correct syntax in case that's what you end up doing.

Skipping MSBuild target

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

msbuild and searching for text

I have a msbuild task that outputs to a file.
Now I want to search that file for a certain text or regex expression and return true if it is there and false if it isn't
any idea of a task that could do this for me?
If you're using MSBuild 4 (with Visual Studio 2010), you can use Property Functions and do this without any custom task:
<IsMyFileMatching>$([System.Text.RegularExpressions.Regex]::IsMatch($([System.File]::ReadAllText("yourfile"), "pattern")))</IsMyFileMatching>