.net - MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML

我一直在研究 MSBuild,因为我需要自动化我的开发商店的构建。我能够轻松编写一个调用 VS 命令提示符并将我的 MSBuild 命令传递给它的 .BAT 文件。这工作得很好,有点漂亮。

这是我的 .BAT 构建文件的内容:

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat"
cd  C:\Sandbox\Solution
msbuild MyTopSecretApplication.sln /p:OutputPath=c:\TESTMSBUILDOUTPUT /p:Configuration=Release,Platform=x86
pause

^ 这很好用,但我现在需要为 TeamCity CI 使用 MSBuild 任务。我曾尝试编写一些 MSBuild 脚本,但无法让它们正常工作。我在 .BAT 文件中使用的命令的等效构建脚本是什么?有什么想法吗?

我尝试过使用类似的东西,但没有成功(我知道这是错误的):

<?xml version="1.0"?>
<project name="Hello Build World" default="run" basedir=".">

<target name="build">
    <mkdir dir="mybin" />
    <echo>Made mybin directory!</echo>

  <csc target="exe" output="c:\TESTMSBUILDOUTPUT">
    <sources>
      <include name="MyTopSecretApplication.sln"/>
    </sources>
  </csc>
  <echo>MyTopSecretApplication.exe was built!</echo>
</target>

<target name="clean">
    <delete dir="mybin" failonerror="false"/>
</target>

<target name="run" depends="build">
  <exec program="mybin\MyTopSecretApplication.exe"/>
</target>

我只需要一个 MSBuild XML 构建脚本,它将 Release模式的单个解决方案编译到指定的输出目录。有什么帮助吗?

最佳答案

使用 MSBuild 任务构建解决方案,传递您需要的属性。

<?xml version="1.0" encoding="utf-8"?>
<Project
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
    ToolsVersion="4.0"
    DefaultTargets="Build">

    <PropertyGroup>
        <OutputDir>c:\TESTMSBUILDOUTPUT</OutputDir>
    </PropertyGroup>

    <ItemGroup>
        <ProjectToBuild Include="MySecretApplication.sln">
            <Properties>OutputPath=$(OutputDir);Configuration=Release</Properties>
        </ProjectToBuild>
    </ItemGroup>

    <Target Name="Build">
        <MSBuild Projects="@(ProjectToBuild)"/>
    </Target>

</Project>

关于.net - MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML 任务脚本中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5119913/

相关文章:

android - 如何加快 android ndk 构建

c# - 是否有 Visual Studio 构建探查器?

build - CodeBuild 执行在构建失败后继续执行,而不是停止

parameters - TeamCity 条件参数值

Maven - 从外部属性文件中读取属性

java - java文件中的Maven版本号

java - 在 Maven 测试阶段禁用 Log4J 日志

qt - Qt的配置有哪些不同的平台

java - 如果未激活另一个配置文件,则激活 Maven 配置文件

c# - 错误构建 VSTS : ## [error] Error: Unable to locat