Friday, August 27, 2010

Modify your build process tutorial

A visual studio project is an MSBuild script. If you would like to modify the project file use any xml or text editor.
You need to unload the project before you modify it...



unload project

… make modifications and then reloaded it again…

reload project

Don’t do this…

You will find the following lines inside any visual studio project
modify comments

…don’t do this. You are better off making minimal changes in the project files. If you write your custom scripts inside seperate files then it's easier to share the msbuild code among your projects.

Organizing your msbuild files

Typically visual studio has reserved the *proj suffix for it’s own files.
c# csproj
visual basic vbproj
c++ vcproj
lightswitch lsproj
vs deployment vdproj
Unless you are creating a new visual studio project template don’t use a *proj suffixed file name. A good recomentation for msbuild filenames is the one that microsoft is using. Take a look inside the “C:\Windows\Microsoft.NET\Framework\v4.0.30319”. You will find some msbuild files there suffixed with *.tasks and *.targets

Microsoft.Common.Tasks
Microsoft.Common.targets
Microsoft.CSharp.targets
Microsoft.Data.Entity.targets
Microsoft.NETFramework.targets
Microsoft.VisualBasic.targets
Microsoft.WinFx.targets
*.Tasks files have only references to dlls with msbuild tasks
tasks file

*.Targets files have all the code (msbuild scripts)
targets file

Creating custom msbuild files for your VS projects

Create 2 msbuild files with a text editor, or even in visual studio (add new xml file).
Example names: My.Tasks & My.Targets

Inside the *.tasks file you reference the necessary tasks

You need to import the *.tasks file insode the targets file
 

BuildDependsOn PropertGroup


The BuildDependsOn propertgroup overrides the BuildDependsOn of the visual studio build process. You can do here all you need. It’s much better than doing it inside the BeforeBuild and AfterBuild targets of the visual studio project file.
The only thing that is left now is to actually import the msbuild script inside the project file. In the following example I make the assumption that my msbuild scripts reside in the same directory as my solution.

Usefull property groups

propgroups

Take a look at your project properties –> build events for nice examples of property groups that are already defined in the default build process.

0 comments:

Post a Comment

Post a comment