C# articles and tutorials on SharpDeveloper.NET

Sharpen your .NET skills with our C# articles, tutorials, demos, and source code by Sameer Alibhai
posts - 63, comments - 53, trackbacks - 1

Updating Your Web.Config From Each Build with CruiseControl

Let's say you have CruiseControl.NET all set up nice and hunky dory.  Now you love the fact that it labels your each build, and you want to somehow show that from your project.  Here is how you can get your CruiseControl.NET project build number into your Web.Config.  This concept can be applied to update any file.
It’s super easy. You will need to add an exec block to your ccnet.config
 
<exec>
                         <!-- Auto increment web.config build number -->
                        <executable>E:\Userdata\CruiseControl\Tools\MergeWebConfigValues.exe (my custom tool)</executable>
                        <buildArgs>"E:\Program Files (x86)\CruiseControl.NET\server\Main.state" e:\userdata\cruisecontrol\Dev_Main\Web.config</buildArgs>
                        <baseDirectory>e:\userdata\cruisecontrol\Dev_Main</baseDirectory>
                        <buildTimeoutSeconds>15</buildTimeoutSeconds>
                  </exec>
 Now all you need to do is write the MergeWebConfigValues.exe
What does it do?
1. It reads the CCNET state file (provided by argument 1) and grabs the last label from there. (The state file is an XML file)
2. It then goes and writes to your Web.Config and updates the build number in there. (or writes to any specified file you like)
Lastly, update your code to read this value by adding some version or about page to read your Web.Config

You now instantly know what version your code is.

Print | posted on Tuesday, June 17, 2008 7:10 PM | Filed Under [ .NET articles Software Engineering ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 5 and 7 and type the answer here:

Powered by: