有关于 MSBuild 脚本的好教程吗?

我正在从事一个 Web 应用程序项目,我需要创建一个构建脚本; 一个构建脚本,我可以从我的巡航控制服务器触发。由于南特已经很多年没有维护了,我认为 MSBuild 才是正确的选择。

我需要构建脚本才能

  • 编译所有程序集
  • 执行单元测试
  • 在单元测试中运行 NCover 分析
  • 部署数据库(取决于参数)。这实际上是在执行一个工具,因为我最终将编写自己的工具来部署数据库。但是该工具的执行应该基于某些命令行参数进行条件化。
  • 以一种 Cruiscontrol 可以阅读和理解的格式交付单元测试和覆盖率结果。

我假设 MSBuild 允许我做所有这些事情。但我不知道从何说起。有没有人知道一个很好的教程,让我开始我的构建脚本?

36395 次浏览

This was my first tutorial. Very easy to understand and follow:

https://codingcockerel.wordpress.com/2008/04/15/automating-the-build-with-msbuild/

I'm looking for info on this subject myself too.

This is a nice article, Versioning Builds with TFS and MSBuild.

I posted a Stackoverflow answer here to a related question, where I also mention this great episode on DnrTV, Sayed Hashimi on MS Build.

I wasted a lot of time before buying the Hashimi MSBuild book, fantastic -- I concur with this review by Steven St Jean.

In addition to an excellent all-round introduction to MSBuild scripting, it has a cookbook section on doing typical build automation thigns like build numbers etc. Obviously the last TeamBuild section will not be directly relevant for you, but a lot of the topics are generic across all CI tools.

UPDATE: The 2nd ed keeps up the trend, adding a must-have section re WebDeploy

I found this MSBuild tutorial by Patrick Smacchia to be very informative (though I read it as a non-beginner)

Also Best Practices for Creating Reusable Builds, Part 1 from MSDN Magazine by Sayed Ibrahim Hashimi and part 2

(And I +1'd the Brennan tutorial)

Check this on MSDN How to: Write a Simple MSBuild Project .

Its good article and had helped me to start.

Here is the pdf of print version of the same .

There is a "Getting Started with MSBuild" blog post on the the Visual Studio Blog which gives a good overview on how MSBuild is hooked up with Visual studio. It's fairly recent (25.02.2010) and uses Visual Studio 2010 and the accompanying MSBuild v4.0.

There is not much code there though.

It wasn't until reading this blog that I understood that the *.csproj files themselves are MSBuild files. And also, that the Build, Clean, Rebuild and Publish command in the project context menu actually are MSBuild "targets".

I wrote this a couple of years ago and try to keep it up to date with new MSBuild features:

http://thomasardal.com/msbuild-tutorial/