Sometimes there are solutions that are technologically so simple that you don’t even think about them.
I develop a couple of projects, some of which are rather complex to build, as they require to generate code from database content.
Build tools can be complex and have a steep learning curve, Powershell might be an overkill since it’s useful if you handle .Net objects and containers, and I found it amazing what you can achieve with a little batch file.
This is a sketch of a project-specific build script:
First, declare log files and required tools. I found tee.pl to both display output on screen and write it to a log file.
set log=C:\path to build\build.log
set tee=perl C:\path to script\tee.pl
set osql=osql -S host -U user -P password -d database -n -w 1000
echo. > %log%
Next, check ASP.Net code for XHTML compliance and other criteria using graspx:
pushd \inetpub\wwwroot\path to web
(call ..\check2) | %tee% %log%
One of my projects uses a metamodel to generate triggers, so generate a T-SQL script to drop and create triggers, and run that script using osql (SQL 2000) or sqlcmd (SQL 2005):
echo generating database stuff from metamodel | %tee% %log%
%osql% -Q "exec Generate_SQL_Code" -o sqlcode.sql
echo run generated code | %tee% %log%
%osql% -i sqlcode.sql | %tee% %log%
Next, generate C# const declarations from database content. (I find it’s a good idea to keep generated in a separate directory):
echo generating Consts.cs | %tee% %log%
%osql% -Q "exec dev_Generate_Consts" -o "C:\path to project\Generated\Consts.cs
The C# source code now matches the constants defined in the database. So we can now initialize the VS environment and build the project:
call "C:\path to\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86
msbuild "C:\path to solution\project.sln"
If we build a web project, delete the PrecompileWeb directory that msbuild created:
rmdir /s /q "C:\path to\Visual Studio 2005\Projects\project\PrecompiledWeb"
Finally, update the online help wiki to include new aspx pages:
What have we got now?
- checked the source code
- generated database objects
- generated C# const definitions
- built VS projects
Next steps are backing up the development database and publishing the application.