What is the MSBuild equivalent to ant's -project-help? - msbuild

I come from an ant background, and I'm starting to use msbuild. I want to create a .proj file with targets for clean, compile, deploy, etc. In ant, I would expect my user to run ant -project-help to get a list of the targets with their descriptions. There doesn't appear to be anything like this with msbuild, so I was thinking of setting DefaultTargets to "Help" and adding this target:
<Target Name="Help">
<Message Text="/t:Clean - Remove all bin folders and generated files"/>
<Message Text="/t:Compile - Generate assembly"/>
<Message Text="/t:Deploy - Install the assembly"/>
</Target>
When I run msbuild, I see this:
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 5/13/2010 9:00:00 AM.
Project "C:\MyProject\MyProject.proj" on node 0 (default targets).
/t:Clean - Remove all bin folders and generated files
/t:Compile - Generate assembly
/t:Deploy - Install the assembly
Done Building Project "C:\MyProject\MyProject.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.05
My target description are hidden among all the other output.
It feels like I have a paradigm-mismatch here. What's the best way to provide the build functionality I want so that users know where to find each target?

I'm afraid there is no clean way to do what you want. Creating a default help target is a good idea.
To have a cleaner output, you could set the Importance attribute of Message task to high to have your messages standing out more.
<Target Name="Message">
<Message Text="/t:Clean - Remove all bin folders and generated files" Importance="high"/>
<Message Text="/t:Compile - Generate assembly" Importance="high"/>
<Message Text="/t:Deploy - Install the assembly" Importance="high"/>
</Target>
You could also run MSBuild with the following argument to clean your output :
msbuild [ProjectFile.proj] /v:m /nologo
You'll have this output :
/t:Clean - Remove all bin folders and generated files
/t:Compile - Generate assembly
/t:Deploy - Install the assembly

Related

MSBuild-Referenced DLLs not copying to output bin

I was a newbie, a little bit knowledge of visual studio, msbuild and scripting.
I was assigned to a task, to create an automation script for building project using MSbuild and the project has three different configuration and I need to build it sequentially because some projects depend on the output dlls of the other configuration, when building the first configuration it succeed but when I reach the second and third configuration it failed. Because reference DLLs were not copied on the ouput bin of selected configuration causing it to missing assembly reference on some projects. And, the thing is I can't edit the projects, it was only for me to view.
Any help on how could I successfully build it.
My script looks like this:
& $msbuild ($master_sln) /t:Clean /p:Configuration=FirstConfiguration /p:Platform="Any CPU"
& $msbuild ($master_sln) /t:Rebuild /p:Configuration=FirstConfiguration /p:Platform="Any CPU"
& $msbuild ($master_sln) /t:Build /p:Configuration="SecondConfiguration" /p:Platform="Any CPU" /p:BuildProjectReferences=false
& $msbuild ($master_sln) /t:Build /p:Configuration="ThirdConfiguration" /p:Platform="Any CPU" /p:BuildProjectReferences=false

How to set the `OutDir` in the command link with Mono's xbuild.exe?

I'm trying to build a c# solution in msysgit (Windows) using the same build command that I would with msbuild:
"C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe" /p:Configuration=Debug /p:OutDir="c:\projects\proudly\build" "src/Proudly.Identity.sln"
With msbuild, the output of the build goes into my /build folder and all is well. Now, when I run the same command with Mono's xbuild, like this:
"C:/Program Files (x86)/Mono/lib/mono/xbuild/12.0/bin/xbuild.exe" /p:Configuration=Debug /p:OutDir="c:\projects\proudly\build" "src/Proudly.Identity.sln"
...and my the build output goes into the /bin/Debug folder of each project instead of my build folder.
I was under the impression that xbuild can be using just like msbuild. Any clue what I'm doing wrong?

Why is my packaging step failing in teambuild?

I'm just the build guy, I didn't write the web app and don't know much about web apps (as will become abundantly clear, I'm sure).
So dude tells me we need to run "msbuild /T:Package /P:Configuration=Release" to package his app. Okay. There's multiple solutions in his build definition and only one of them which needs the Package target so I wrote a stupid little msbuild proj file to add to his TFS build definition with a default target that looks like this:
<Target Name="Package" Condition=" '$(Configuration)' == 'Release' ">
<MSBuild Projects="HisApp.csproj"
Properties="Configuration=$(Configuration)"
Targets="Package" />
</Target>
Added that to the build definition and it fails with this:
Build started 8/7/2012 7:17:48 PM.
Project "C:\path\to\MyDumbScript.proj" on node 1 (default targets).
Package:
Project "C:\Path\to\MyDumbScript.proj" (1) is building "C:\Path\to\HisApp.csproj" (2) on node 1 (Package target(s)).
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Value cannot be null. [C:\Path\to\HisApp.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Parameter name: type [C:\Path\to\HisApp.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Unknown error (0x80005000) [C:\Path\to\HisApp.csproj]
Done Building Project "C:\Path\to\HisApp.csproj" (Package target(s)) -- FAILED.
Done Building Project "C:\Path\to\MyDumbScript.proj" (default targets) -- FAILED.
Build FAILED.
"C:\Path\to\MyDumbScript.proj" (default target) (1) ->
"C:\Path\to\HisApp.csproj" (Package target) (2) ->
(GetProjectWebProperties target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Value cannot be null. [C:\Path\to\HisApp.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Parameter name: type [C:\Path\to\HisApp.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1737,5): error : Unknown error (0x80005000) [C:\Path\to\HisApp.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:00.82
So that's as clear as mud.
Questions:
Is there some more straightforward way to call the package target from Team Build when the build definition calls multiple solutions?
Why's this failing?
Thanks.
It looks like the errors were due to IIS not being enabled on the build machine.
When I enabled the “Web Management Tools” and “World Wide Web Services” features on the build machine the build failed in new and more interesting (and less opaque) ways.
As for the question of how better to call the package target from Team Build, I'd be happy to hear answers, but this works now.

MSBuild cannot build my x86 program

I have a program called A. It produces a file, A.exe. A.exe MUST run as a x86 program, and is thus build as one. A.exe refers to B.dll and C.dll.
B.dll and C.dll is set to build as x86 programs to make them available to A.exe
I am fairly new to this building with msbuild.exe so im still learning. I made a buildfile that uses the msbuild task to build my application (A)'s project (.csproj) file. I can easily build everything from within Visual Studio.
When i build from my msbuild (commandline) i get this error: "An attempt was made to load an assembly with an incorrect format B.exe.
<Target Name="Compile">
<Message Text="Compiling"/>
<ItemGroup>
<myproject Include="A.csproj"/>
</ItemGroup>
<MSBuild Projects="#(myproject)" Properties="Configuration=Release;Platform=x86"/>
</Target>
There is no need to build the dlls as x86. They should be build for any platform. When they are loaded by a .exe built for x86 the JIT compiler will compile them for the target chosen for the .exe (i.e. x86 if the .exe is built for x86).
Can't help you with msbuild though :-)

How do I set the Output directory for a C++ project built by msbuild?

I have a MSBuild .proj file that is compiling a mixture of C# and C++ projects.
The C# projects compile output (.exe/.dlls) to the OutputPath I specify, but when I specify OutputPath for the C++ projects (which calls vcbuild.exe), the OutputPath is ignored and instead goes into the directory specified in the Property Pages for the .vcproj.
Here's my MSBuild task:
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>
How can I specify that the C++ output files should go to the same directory as the C# output files $(ToolsOutputDir)?
I was able to make this work by doing the following:
1) Installing the Microsoft SDC MSBuild Tasks Library
2) In the property pages for the C++ projects, setting the output directory to $(OutputPath).
3) Adding a SDC task to set the environment variable OutputPath before building the C++ projects via VCBuild:
<Microsoft.Sdc.Tasks.SetEnvironmentVariable Variable="OutputPath" Value="$(ToolsOutputDir)" Target="Process"/>
<!-- Build any CPP code x86 -->
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>