Wednesday, July 11, 2007

Automate your build

Doing things manually sucks.
Thats why we develop software, because people are sick of doing things the hard way.
Seeing as our job is automation, it amazes me that so many people are still developing software the hard way.

What am I talking about? Builds.

Right now at my office, whenever a change is made and we need to update our test sever, we must produce a build. And right now, we're using the VS2005 IDE, cleaning the solution, building the solution, and publishing the website by hand.

Furthermore, once that is complete, we have to go in and delete certain files from our published site, and then copy it over.

There are several markup languages for a task like this with the main ones being MSBuild and Nant. However if you want to skip all that, the process can be easily automated with a batch file.


cd\
cd "program files\microsoft visual studio 8\common7\ide\"
devenv /clean release "C:\Dev\MyProject\Project.sln"
devenv /build release "C:\Dev\MyProject\Project.sln"
rd "C:\Dev\Precompiled Webs\MyProject" /s /q
cd\
cd "WINNT\Microsoft.NET\Framework\v2.0.50727"
aspnet_compiler -v /Website -p "C:\Dev\MyProject\Website" "C:\Dev\Precompiled Webs\MyProject"
cd\
cd "dev\precompiled webs\MyProject"
del *.log /f /s /q
del *.pdb /f /s /q


lets look at whats going on


cd\
cd "program files\microsoft visual studio 8\common7\ide\"
devenv /clean release "C:\Dev\MyProject\Project.sln"
devenv /build release "C:\Dev\MyProject\Project.sln"


this uses the devenv command line to clean and build your solution without using the IDE


rd "C:\Dev\Precompiled Webs\MyProject"


This deletes the folder where the compiled site will need to go


cd\
cd "WINNT\Microsoft.NET\Framework\v2.0.50727"
aspnet_compiler -v /Website -p "C:\Dev\MyProject\Website" "C:\Dev\Precompiled Webs\MyProject"


Here we use the aspnet_compiler utility to compile the site.
-v is the virtual path (the name of your website within the solution)
-p is the path to your website
and the last path is where the compiled site will end up


cd\
cd "dev\precompiled webs\MyProject"
del *.log /f /s /q
del *.pdb /f /s /q
del web.config /f /q


Lastly, I want to remove any pdb and log files, as well as the web.config because our test server has a different config file from the development machine

Here are a few links that may help you with your batch file:
aspnet_compiler info
devenv command line info
MS-DOS commands