MSBuild - How to build a .NET solution file (in an XML task script) from pre-written command line commands(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 - 如何从预先编写的命令行命令构建 .NET 解


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01