Monday, November 13, 2006

There were a couple of posts in the MSBuild forum recently related to customizing the build process. The specific thread is, Forcing a Clean build. The question boils down to, "How do you force a clean each time I build?" The answer lies in adding the Clean target to the build targets dependency list. You can read details on how this works in my MSDN article Inside MSBuild.
One of the participants asked me to post a complete solution of how to do this. So that response is this entry. I created a sample Windows Application that has the build process customized. I called this BeforeBuildEx, you can download all the files at the end of this entry. I modified the WindowsApplication1.csproj file and added the following lines:

<PropertyGroup>

   <BuildDependsOn>

      Clean;

      MyBeforeBuild;

      $(BuildDependsOn);

      MyAfterBuild

   </BuildDependsOn>

</PropertyGroup>

 

<Target Name="MyBeforeBuild">

   <Message Text="This is before the build." Importance="high"/>

</Target>

 

<Target Name="MyAfterBuild">

   <Message Text="This is after the build." Importance="high"/>

</Target>

The list of targets that must be executed for a build is contained in the BuildDependsOn list. So if you change that list, you change to build process. If you want to add a target before the build process, add that target to the begining of the list. In the above statement, I'm actually extending the previous list by adding my targets. I add 2 targets before and 1 after the already existing definiton for BuildDependsOn. Much more detail about this in my article. The snippet above was inserted after the statement

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

This is very important, otherwise your customizations may be overwritten. Now if you build this you will see that the Clean target is executed when the application is built. If you want to see this in Visual Studio you have to increase the verbosity of the MSBuild output that is shown on the Output window. Do this by: Tools->Options->Projects and Solutions->Build and Run and set the value for MSBuild project build output verbosity to atleast Normal. The link to the zip file is below. In some cases this could cause some problems for Visual Studio.

BeforeBuildEx.zip

Sayed Ibrahim Hashimi

Monday, November 13, 2006 4:11:06 AM (GMT Standard Time, UTC+00:00)  #    Comments [5]  | 
Saturday, September 22, 2007 2:17:51 AM (GMT Daylight Time, UTC+01:00)
hi there! Nice topic. Welcome to hallowen!
Tuesday, October 09, 2007 1:26:30 PM (GMT Daylight Time, UTC+01:00)
This site is interesting and very informative, nicely interface. Enjoyed browsing through the site
Monday, December 03, 2007 12:50:13 AM (GMT Standard Time, UTC+00:00)
This is great! One question: Is there any way around the authentication issue? I have a portal which requires a login/password. Am I out of luck?
Thursday, December 06, 2007 8:30:23 AM (GMT Standard Time, UTC+00:00)
This is worlds of the [url=http://www.sidite-solar.com/index.html]solar water heaters[/url][url=http://www.sidite-solar.com/about.html]solar hot water heaters[/url][url=http://www.sidite-solar.com/solar_water_heater.html]solar collector[/url][url=http://www.sidite-solar.com/chinasolar/index.asp]太阳能热水器[/url][url=http://www.sidite-solar.com/chinasolar/company.asp] 太阳能[/url][url=http://www.sidite-solar.com/chinasolar/works2.asp]太阳能热水工程[/url]
Friday, February 12, 2010 8:40:02 AM (GMT Standard Time, UTC+00:00)
Evergreen solar water heater co.,ltd , specilized in china solar energy system,including solar collector, active split solar water heater ,pre-heating solar water heater ,high pressure compact solar water heater ,passive China solar water heater ,solar water heater project system.

http://www.solar-water-heater-china.com/
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, strike, strong, sub) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

Theme design by Jelle Druyts