我们给MSBuild项目构建文件起什么名字?

时间:2020-03-06 14:34:12  来源:igfitidea点击:

我正在尝试学习如何使用MSBuild,以便我们可以使用它来构建我们的项目。文档中似乎有一个很大的漏洞,在我所看到的任何地方都可以找到漏洞,该漏洞就是我们如何命名或者指定MSBuild项目文件?

例如,可以从Microsoft下载的MSBuild教程详细介绍了构建文件的内容。例如,这是他们的Hello World项目文件的一点点。

<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>

它继续等等,等等,项目等等等等任务,这是操作方式,这也是操作方式。没用,完全没用。因为他们从来没有说过MSBuild应用程序应该如何识别此xml文件。是否应该以特定的方式命名?是否应该将其放置在特定目录中?两个都?两者都不?

他们不仅仅是不讲MS教程。我也无法在MSDN或者我可以从Groups.Google拔出的任何链接上找到它。

这里有人知道吗?我当然希望如此。

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.

解决方案

我们可以根据需要命名文件。从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]

因此,如果将文件另存为mybuildfile.xml,则可以使用以下语法:

msbuild.exe mybuildfile.xml

还是对于像我这样的真正懒惰的人。

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

如果遵循以下策略,则无需指定构建文件:

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.

这来自"新功能反馈请求":/ IgnoreProjectExtensions新的命令行开关。

我总是将手动编写的脚本命名为build.proj。