Is there a way to specify the output like
msbuild zlibvc.sln /t:zlibvc /p:OUT=$(OutDir)\zlib1.dll
by example, changing the output from the standard zlibwapi.dll to zlib1.dll ?
In case of C# projects, we do modify csproject file in the following two places like this:
Before:
<AssemblyName>zlibwapi.dll</AssemblyName>
and
<OutputPath>bin\</OutputPath>
After:
<ZLibAssemblyName Condition="$(ZLibAssemblyName) == '' ">zlibwapi.dll</ZLibAssemblyName>
<AssemblyName>$(ZLibAssemblyName)</AssemblyName>
and
<ZLibOutputPath Condition="$(ZLibOutputPath) == '' ">bin\</ZLibOutputPath>
<OutputPath>$(ZLibOutputPath)</OutputPath>
Then call your msbuild command like below:
msbuild zlibvc.sln /t:zlibvc /p:ZLibOutputPath=$(OutDir)\ /p:ZLibAssemblyName=zlib1.dll
Hope this or a similar thing works in vcbuild task as well.
Related
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
Our MSBuild scripts use the Exec task to call a few command line applications. Most of these applications have their own output verbosity settings which I would like to have be the same as the verbosity level of the MSBuild script calling them.
Is there a way for me to get the logging verbosity level of my MSBuild process?
I thought I could write a custom task to handle this, but poking around the MSBuild API, I couldn't find any properties or classes that would give me the verbosity level.
Shortly after asking my questions, I noticed that MSBuild 4 exposes System.Environment.CommandLine as a property function, which should include any verbosity arguments. With the following bit of parsing, you can create several boolean properties that will tell you the current logging level:
<PropertyGroup>
<CommandLine>$([System.Environment]::CommandLine.Trim().ToLower())</CommandLine>
<IsQuietVerbosity>False</IsQuietVerbosity>
<IsMinimalVerbosity>False</IsMinimalVerbosity>
<IsNormalVerbosity>True</IsNormalVerbosity>
<IsDetailedVerbosity>False</IsDetailedVerbosity>
<IsDiagnosticVerbosity>False</IsDiagnosticVerbosity>
</PropertyGroup>
<PropertyGroup Condition="'$(CommandLine.Contains("/v"))' == 'True'">
<IndexOfLastVerbosityArg>$(CommandLine.LastIndexOf("/v"))</IndexOfLastVerbosityArg>
<IndexOfVerbosityArg>$(CommandLine.IndexOf(":", $(IndexOfLastVerbosityArg)))</IndexOfVerbosityArg>
<IndexOfVerbosityArg>$([MSBuild]::Add($(IndexOfVerbosityArg), 1))</IndexOfVerbosityArg>
<IndexOfEndOfVerbosityArg>$(CommandLine.IndexOf(" ", $(IndexOfVerbosityArg)))</IndexOfEndOfVerbosityArg>
<IndexOfEndOfVerbosityArg Condition="'$(IndexOfEndOfVerbosityArg)' == '-1'">$(CommandLine.Length)</IndexOfEndOfVerbosityArg>
<LengthOfVerbosityArg>$([MSBuild]::Subtract($(IndexOfEndOfVerbosityArg), $(IndexOfVerbosityArg)))</LengthOfVerbosityArg>
<VerbosityLevel>$(CommandLine.Substring($(IndexOfVerbosityArg), $(LengthOfVerbosityArg)).Trim())</VerbosityLevel>
<IsQuietVerbosity>$(VerbosityLevel.StartsWith('q'))</IsQuietVerbosity>
<IsMinimalVerbosity>$(VerbosityLevel.StartsWith('m'))</IsMinimalVerbosity>
<IsNormalVerbosity>$(VerbosityLevel.StartsWith('n'))</IsNormalVerbosity>
<IsDiagnosticVerbosity>$(VerbosityLevel.StartsWith('di'))</IsDiagnosticVerbosity>
<IsDetailedVerbosity Condition="'$(IsDiagnosticVerbosity)' == 'False'">$(VerbosityLevel.StartsWith('d'))</IsDetailedVerbosity>
</PropertyGroup>
Remember, this will only work in MSBuild 4+.
Ugly? Yup. Kludgy? Maybe. Does it work. Yup!
You can't : http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/510f07b4-c5f7-43a8-b7cb-e3c398841725/
Instead, you can set a property of yours (passing it with the command line for example) which contains the verbosity level.
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
I am trying to call MSBuild from a command line. Everything was working fine when I was using a path that had no spaces, but now I have a path that has spaces and the command is failing.
Command (works):
"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
/t:Rebuild "C:\Projects\myProject.csproj"
/p:OutDir=c:\temp\deploy\funAndGames\Deployment\bin\
/p:WebProjectOutputDir=c:\temp\deploy\funAndGames\Deployment\
/p:Configuration=Release
I then added quotes and changed OutDir to OutPath (doesn't work):
"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
/t:Rebuild "C:\Projects\myProject.csproj"
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\"
/p:WebProjectOutputDir="c:\temp\deploy\funAndGames\Deployment\"
/p:Configuration=Release
What I am aiming for is something like this (doesn't work):
"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
/t:Rebuild "C:\Projects\myProject.csproj"
/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\"
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\"
/p:Configuration=Release
Any help on the syntax around OutDir/OutPath and WebProjectOutputDir with spaces? Is it possible? If it isn't does anyone know what the reason is (due to some Url's not having spaces type thing?)
Just found this out an answer to this old question.
To handle spaces, you should use the escape character \ on all folders. Basically
/p:OutPath="c:\temp\deploy\fun and games\Deployment\bin\"
should be
/p:OutPath="c:\\temp\\deploy\\fun and games\\Deployment\\bin\\"
and magically it works!
Try add "
ex:
/p:OutPath=""c:\temp\deploy\fun and games\Deployment\bin\""
Msbuild also seems to work with spaces in the OutDir if you switch \ to /, while using quotes:
/p:OutDir="c:/temp/deploy/fun and games/out/"
/p:WebProjectOutputDir="c:/temp/deploy/fun and games/Deployment/"
For me the working solution is:
/p:SQLCMD="\"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE\""
In other words: Putting all the string into quotes (the external quotes aren't passed as value to MSBuild).
The value inside MSBuild for this property is: "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" (with the quotes).
> "C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
> /t:Rebuild
> "C:\Projects\myProject.csproj"
/p:OutPath="c:\temp\deploy\funAndGames\Deployment\bin\"
----------------------------------------
/p:WebProjectOutputDir="c:\temp\deploy\fun and games\Deployment\"
----------------------------------------
> /p:Configuration=Release
Try this.
Also try via VSStudio GUI. Then copy the settings & try with MS Build.
If you have multiple parameters in a switch you can't really 'avoid' the problem by fixing the path. What you can do is put your parameters of the switch between " some_parameters1 some_parameters2 ".
Something like:
<Exec Command="SomeCommand /useMultipleParameterSwitch="value1:blabla1 | value2:blabla2""/>
Of course a lot depends of the syntax of the switches but that works for me and my team.
To do this when using a .proj file and your path is included in properties like $(DeployFolder) and $(NuGetExe), you can use """ like this:
<Exec Command=""$(NuGetExe)" pack -OutputDirectory "$(DeployFolder)"" />