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. VisualStudio自动编码插件(Autocode——devprojects.net)

    今天无意之中发现了一个VS插件,功能还不错,推荐给大家.官网http://www.devprojects.net/ 有以下一些功能: 智能感知! 快速命令调用,只需按Ctrl +回车 T4和ASPX一 ...

  2. htop基本使用

    一.什么是htop? top是所有类unix系统的必备工具,能直观方便的查看到系统负载.内存及进程等信息. 而htop具有top工具的全部功能且还新增了一些额外的功能和使用体验改进.与top相比,其具 ...

  3. HTML&CSS学习心德

    学了html&css一周的时间,每天上课9小时,有空就看一下HTML+div+CSS视频,感觉还不错. 基本思路:从大的方面(整体结构)着手,将HTML的基本知识"解构"然 ...

  4. 【LeetCode OJ】Recover Binary Search Tree

    Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder ...

  5. Struts2框架下表单数据的流向以及映射关系

    本例框架很简单:默认页面为用户登录界面login.jsp,提交后由action类LoginAction.java来判断成功或失败,登录结果分别由success.jsp和failure.jsp呈现. 一 ...

  6. pdf生成器

    apose, http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version

  7. 学习maple

    定义函数:$f:=(x,y) \rightarrow x^2+y^2$ 类似mathematica的manipulate功能:plots[animate](plot,[f(x,y),x=0..1],y ...

  8. jdbc mysql写入中文乱码解决

    一. 问题 数据库编码:utf8 mysql> create database dbnameDEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ...

  9. The requested operation has failed apache

    在安装apache后, 启动apache时提示The requested operation has failed错误: 通过一排除 cd apache 安装的Bin目录cmd如下秘密(双引号中的内容 ...

  10. -webkit-overflow-scrolling : touch;快速滚动标签

    http://www.cnblogs.com/PeunZhang/p/3553020.html(链接出处,只是转载学习) 对于如何使用弹性滚动,这里并没有最好的方案,具体看产品的用户群.产品的定位等, ...