tags:

views:

767

answers:

3

I am trying to learn how to use MSBuild so we can use it to build our project. There's what seems to be a very big hole in the documentation, and I find the hole everywhere I look, the hole being how do you name or otherwise designate the MSBuild project file?

For example, the tutorial on MSBuild that can be downloaded from Microsoft goes into some detail on the contents of the build file. For example, here's a little bit of their Hello World project file.

<Project MSBuildVersion = "1.0" DefaultTargets = "Compile">
   <Property appname = "HelloWorldCS"/>
   <Item Type = "CSFile" Include = "consolehwcs1.cs"/>
   <Target Name = "Compile">
      <Task Name = "CSC" Sources = "@(CSFile)">
         <OutputItem  TaskParameter = "OutputAssembly" Type = "EXEFile" Include = "$(appname).exe"/>
      </Task>
      <Message Text="The output file is @(EXEFile)"/>
   </Target>
</Project>

And it goes on blah, blah, blah Items blah blah blah tasks, here's how you do this and here's how you do that. Useless, completely useless. Because they never get around to saying how this xml file is supposed to be recognized by the MSBuild app. Is it supposed to be named in a particular way? Is it supposed to be placed in a particular directory? Both? Neither?

It isn't just the MS tutorial where they don't tell about it. I haven't been able to find it on MSDN, or on any link I can wring out of Groups.Google, either.

Does someone here know? I sure hope so.

Edited to add: I mistook the .proj file included in the tutorial to be the .csproj file and that is what one fed to MSBuild, but it took the answer below before I saw this. It should have been rather obvious, but I missed it.

+3  A: 

You can name the file as you see fit. From the help for MSBuild

msbuild.exe /?

Microsoft (R) Build Engine Version 2.0.50727.3053
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Syntax:              MSBuild.exe [options] [project file]

So if you save the file as mybuildfile.xml you would use the syntax:

msbuild.exe mybuildfile.xml
palehorse
A: 

Or for the truly lazy, like me.

msbuild.exe project-file-name.vcproj /t:Rebuild /p:Configuration=Release
kenny
+1  A: 

You don't have to specify the build file if you respect following strategy:

Today, when you invoke msbuild.exe from the command line and don't specify any project files as arguments, then we do some auto inferral and scanning and decide if we should build anything. If we find either a msbuild project (anything that has an extension of *proj) or a solution file (.sln), we will build either the project or the solution as long as there is only one solution or one project in the directory. If there is a solution and a project, we will give preference to the solution. If there's more than one project or more than one solution, we issue an error message because we can't decide which one to build.

This is taken from New Feature Feedback Request: /IgnoreProjectExtensions - A new command-line switch.

I always name my manually written scripts build.proj.

Thomas Freudenberg