问题描述
我一直在研究 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 任务脚本中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!