MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML 任务脚本中)

MSBuild - How to build a .NET solution file (in an XML task script) from pre-written command line commands(MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML 任务脚本中))
本文介绍了MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML 任务脚本中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I have been studying MSBuild as I have the need to automate my development shop's builds. I was able to easily write a .BAT file that invokes the VS command prompt and passes my MSBuild commands to it. This works rather well and is kinda nifty.

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

Here is the contents of my .BAT build file:

call "C:Program Files (x86)Microsoft Visual Studio 10.0VCinamd64vcvars64.bat"
cd  C:SandboxSolution
msbuild MyTopSecretApplication.sln /p:OutputPath=c:TESTMSBUILDOUTPUT /p:Configuration=Release,Platform=x86
pause

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

^ This works well but I now have the need to use the MSBuild task for TeamCity CI. I have tried to write a few MSBuild scripts but I cannot get them to work the same. What is the equivalent build script to the command I am using in my .BAT file? Any ideas?

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

I have tried using something like this, but no success (I know this is wrong):

<?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="mybinMyTopSecretApplication.exe"/>
</target>

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

推荐答案

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

Use the MSBuild task to build the solution passing the properties you need.

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

这篇关于MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML 任务脚本中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)