Features of MSbuild
I am new to MSBuild and开发者_如何转开发 have a couple of questions:
What things can we achieve using MSBuild?
Is it possible to do testing using MSBuild?
How can I integrate MSBuild with TFS? What are the advantages of doing so?
1 - http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx
2 - Yes
3 - TFS Build runs MSBuild targets. It gives you continuous integration which alerts you to failures earlier.
As an example for #1, a script I worked on last week did the following
- Clean and rebuilt all needed projects in Release mode
- Remove unneeded files (pdbs, random xml files, etc), and copied in additional dependancies (release versions of configuration files, etc)
- Generated an installer cab for Windows Mobile
- Gzip'd the cab, to be included in another cab (Long story...)
- Built the second cab
- Copied user training documentation into the target directory
- Zip up the target directory for distribution to the customer.
So, now this entire process can be done quickly, and in a 100% reproducible manner, even on someone else's machine.
This was my first major MSBuild script, built over the course of two work days (Not solidly working on it the whole time, mainly when waiting for people to respond). Almost all was done with MSBuild out of the box. The zipping came from MSBuild Extension Pack, and the wrapper around the cabwiz tool to make cabs came from ctacke's blog. The Gzip task was created in about 10 minutes with minimal knowledge of how to write MSBuild tasks, and the Gzip library from System.Web.Compression.
A quick look yields the msbuildtasks project, which includes a NUnit task. Look through the list of tasks on that site for an idea of some of the things that can be done.
What things can we achieve using MSBuild?
You can nearly do everything you need when you do a manual deploy of you application. Mainly:
Compiling the last version of your code
Create and delete backups
Create specific config files (web.configs/app.configs) for different environments
Deploy to any environment
Make some smoke tests to deployed builds and if they fail recover automatically backups
If there is anything that you can't do maybe someone programmed something (see for example this useful site http://msbuildtasks.tigris.org) or you can program it yourself.
Is it possible to do testing using MSBuild?
Yes. You can run your a subset of your unit tests (or all of them) and see the results, making the build fail or have a warning if any test fail. Example pic:
How can I integrate MSBuild with TFS? What are the advantages of doing so?
Mainly your build script will get the latest version of code from TFS. You can also have labeled builds (f.e: alpha1, alpha2, etc.) and see in each build which changesets were included.
The main point of using TFS/MSBuilds is having continuous integration making at least an automatic daily/nightly build or even better automatically building every time that someones check in some code (if the project is small). This way you
New to msbuild you say ... well, msbuild is an xml based metalanguage used primarily to drive the compilation of code. As a metalanguage it can be used to do pretty much anything. The main building blocks within it are Tasks. Apart from the standard tasks built in, you can write custom tasks in c# and therefore you have no limitation on what msbuild can do. Plus the built in Exec task means you can invoke any exe.
Now, that's looking at what it can do, not what it is best at. The strength in msbuild is the incremental build aspect. As I said earlier, it is primarily to drive the compilation of code. The incremental build feature is there to make builds quicker as only changed files cascade their output. This is an advanced aspect of msbuild but where its strength lies.
Can it be used for testing? Well as it can do anything of course it can. If you use TFS2005/8 then the teambuild msbuild script that is invoked already does the testing and publishes the results back to the TFS server. (The same is possible in TFS2010 but only using the Upgrade build template).
Integration with TFS depends on what you mean by it. Msbuild was the build engine for TFS2005/8 and therefore it didn't get much more integrated than that. On TFS2010 it is still used to compile the solutions but WF4 is the build engine now. For compatibility all the msbuild tasks for TFS2005/8 are also available in TFS2010.
So, if you use TFS then from one perspective you already are integrating msbuild and TFS.
精彩评论