msbuild是微软提供的一个用于生成应用程序的平台,你可以通过一个xml配置文件来控制和处理你的软件工程。它也集成到了vs里面,它不依赖于vs。

xml配置(架构)的组成元素:

  •   项目文件

      属性

      项

      任务

      目标

属性: 
<PropertyGroup>
<AssemblyName>MSBuildSample</AssemblyName>
<OutputPath>Bin\</OutputPath>
</PropertyGroup>
项: 
<ItemGroup>
<Compile Include="helloworld.cs" />
</ItemGroup>
任务:
    <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
目标:目标是将一些任务有顺序的组合到一起
<Target Name="Build">
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>

下面是msdn上面一个最简单的xml构架文件:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="helloworld.cs" />
</ItemGroup>
<Target Name="Build">
<Csc Sources="@(Compile)"/>
</Target>
</Project>

该文件通过一个任务编译helloworld.cs文件。

下面是一个完整的构建一个c/s架构应用程序的简单示例:

xml文件定义的属性:
<PropertyGroup>
<OutDir>output</OutDir>
<OutServerDir>$(OutDir)server</OutServerDir>
<OutClientDir>$(OutDir)client</OutClientDir>
<SolutionFile>..\xx\你的工程文件.sln</SolutionFile>
<ServerDir>xx\xx\工程编译后bin\server目录</ServerDir>
<ClientDir>xx\xx\工程编译后bin\client目录</ClientDir>
</PropertyGroup>
xml文件定义的项:
<ItemGroup>
<ServerDirFiles Include="$(ServerDir)\**\*.*" Exclude="你要排除的文件定义"/>
<ClientDirFiles Include="$(ClientDir)\**\*.*" Exclude="你要排除的文件定义"/>
</ItemGroup>
xml文件定义的任务列表:
  1. Clean
  2. Init
  3. Build
  4. Relesase  
  <Target Name="Clean">
<RemoveDir Directories="$(OutDir)"/>
</Target> <Target Name="Init" DependsOnTargets="Clean">
<MakeDir Directories="$(OutDir)"/>
<MakeDir Directories="$(OutServerDir)"/>
<MakeDir Directories="$(OutClientDir)"/>
</Target> <Target Name="Build" DependsOnTargets="Init">
<MSBuild
Projects="$(SolutionFile)"
Targets="Rebuild"
Properties="Configuration=Release"/>
</Target> <Target Name="CopyFiles" DependsOnTargets="Build">
<Copy
SourceFiles="@(ServerDirFiles)"
DestinationFiles="@(ServerDirFiles->'$(OutServerDir)\%(RecursiveDir)%(Filename)%(Extension)')"/>
<Copy
SourceFiles="@(ClientDirFiles)"
DestinationFiles="@(ClientDirFiles->'$(OutClientDir)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
以上几个片段的汇总:
<Project DefaultTargets="CopyFiles" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir>output</OutDir>
<OutServerDir>$(OutDir)server</OutServerDir>
<OutClientDir>$(OutDir)client</OutClientDir>
<SolutionFile>..\xx\你的工程文件.sln</SolutionFile>
<ServerDir>xx\xx\工程编译后bin\server目录</ServerDir>
<ClientDir>xx\xx\工程编译后bin\client目录</ClientDir>
</PropertyGroup> <ItemGroup>
<ServerDirFiles Include="$(ServerDir)\**\*.*"/>
<ClientDirFiles Include="$(ClientDir)\**\*.*"/>
</ItemGroup> <Target Name="Clean">
<RemoveDir Directories="$(OutDir)"/>
</Target> <Target Name="Init" DependsOnTargets="Clean">
<MakeDir Directories="$(OutDir)"/>
<MakeDir Directories="$(OutServerDir)"/>
<MakeDir Directories="$(OutClientDir)"/>
</Target> <Target Name="Build" DependsOnTargets="Init">
<MSBuild
Projects="$(SolutionFile)"
Targets="Rebuild"
Properties="Configuration=Release"/>
</Target> <Target Name="CopyFiles" DependsOnTargets="Build">
<Copy
SourceFiles="@(ServerDirFiles)"
DestinationFiles="@(ServerDirFiles->'$(OutServerDir)\%(RecursiveDir)%(Filename)%(Extension)')"/>
<Copy
SourceFiles="@(ClientDirFiles)"
DestinationFiles="@(ClientDirFiles->'$(OutClientDir)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>

在使用这个msbuild xml文件的时候你可以写一个批处理命令:

@echo off
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\msbuild build.xml /nologo /v:m
pause

  

用msbuild构建应用的更多相关文章

  1. [Powershell]使用Msbuild构建基于.NET Framework的WebAPI项目

    查找最高版本的MsBuildTools. 清理缓存垃圾. 还原NuGet包. 构建解决方案. 按项目发布程序到本地. 按项目ZIP打包. <# .NOTES ================== ...

  2. 使用MSBUILD 构建时出错 error MSB3086: Task could not find "sgen.exe" using the SdkToolsPath的解决方法

    如果项目有添加有WB引用,比如引用其它网站的WEB服务等,那么VS在编译时会自动生成个 [项目名称].Serializers.dll的文件,就是把引用服务中的相关对象信息生成硬编码的程序集,以提高效率 ...

  3. 使用MSBUILD 构建时出错 error MSB3086: 任务未能使用 SdkToolsPath“”或注册表项“XXX”找到“LC.exe”,请确保已设置 SdkToolsPath。

    如果项目有添加有WB引用,比如引用其它网站的WEB服务等,那么VS在编译时会自动生成个 [项目名称].Serializers.dll的文件,就是把引用服务中的相关对象信息生成硬编码的程序集,以提高效率 ...

  4. 用MSBuild和Jenkins搭建持续集成环境(2)

    http://www.infoq.com/cn/articles/MSBuild-2   作者 Mustafa Saeed Haji Ali ,译者 李剑 发布于 2012年10月23日 | 注意:  ...

  5. 用MSBuild和Jenkins搭建持续集成环境(1)

     http://www.infoq.com/cn/articles/MSBuild-1 你或其他人刚刚写完了一段代码,提交到项目的版本仓库里面.但等一下,如果新提交的代码把构建搞坏了怎么办?万一出现编 ...

  6. 用MSBuild和Jenkins搭建持续集成环境 - 转

    http://www.infoq.com/cn/articles/MSBuild-1 http://www.infoq.com/cn/articles/MSBuild-2 MSBuild是在.NET ...

  7. .Net Core迁移到MSBuild的多平台编译问题

    一.前言 本篇主要讨论.NET Core应用程序项目结构的主题,重点探索.NET Core应用程序的多平台编译问题,这里指的多平台是指.NET Framework..NET Core App..NET ...

  8. jenkins部署.net平台自动化构建

    在引入自动化部署工具的时候,我们对比了jenkins和gitlab CI,jenkins有非常丰富的插件,配置起来方便.gitlab CI更倾向于脚本配置,当然jenkins也可以使用pipeline ...

  9. 用MSBuild和Jenkins搭建持续集成环境(1)[收集]

    你或其他人刚刚写完了一段代码,提交到项目的版本仓库里面.但等一下,如果新提交的代码把构建搞坏了怎么办?万一出现编译错误,或者有的测试失败了,或者代码不符合质量标准所要求的底限,你该怎么办? 最不靠谱的 ...

随机推荐

  1. php大力力 [051节] 支付宝支付.申请支付资质,等待审核中

    https://beecloud.cn/doc/payapply/?index=6 支付宝支付申请支付资质 一.注册支付宝用户 在支付宝官网注册成为用户 二.签约对应支付产品 应用集成支付宝支付,需要 ...

  2. UE4 代码编写细节:静态变量

    Note:因为在切换关切时,会GC掉所有GameThread线程下的Object类,如果Static是UOBject 请调用AddToRoot函数  当然如果你的UObject子类Object是在自己 ...

  3. Maven项目pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. amazon oa2 - insert a value into a cycled linked list

    遍历,一共有三种情况, 1. pre <= x <= current 2. 遍历到了head时,x>tail 或者 x<=head (不会等于tail) 3. 遍历回aNode ...

  5. vfp 智能感知拓展应用

    *======================================================================================== * * Versio ...

  6. ansible代码分析第一篇--主文件—ansible分析

    2016年2月23日,学习,分析ansible代码 ansible是一种运维中使用的批量部署的工具,它本身是一种框架,具体的部署和架构分析,下面这篇文章讲的不错. http://os.51cto.co ...

  7. C#、js、json Datetime格式总结

    在工作过程中遇到时间格式的数据在C#.js 和 json保存的不同结果,现在总结一下 JavaScript Parser: 1.数字型时间转字符串时间 如var data = "/Date( ...

  8. android 打开各种文件(setDataAndType)转:

    android 打开各种文件(setDataAndType) 博客分类: android-->非界面 android 打开各种文件 setDataAndType action动作  转自:htt ...

  9. php判断json对象是否存在的方法

    在实际测试中php读取json数组时 使用简单的 if 或者 array_key_exists 去判断对象是否存在是会报错的,以下是google搜寻的正确判断方法 实际上出现报错只是我对php还不是很 ...

  10. 使用 AdaBoost 元算法提高分类器性能

    前言 有人认为 AdaBoost 是最好的监督学习的方式. 某种程度上因为它是元算法,也就是说它会是几种分类器的组合.这就好比对于一个问题能够咨询多个 "专家" 的意见了. 组合的 ...