In my previous post, Building Visual Studio Solutions from the Command Line, I described the basic steps to be performed when one of my projects is to be built completely, or code needs to be generated.
This post gives a more detailed view of what is going on in the batch file. (Each batch file needs to be adjusted to the project it is used for in terms of functionality)
Handle batch parameters
Each function of the batch file can be invoked by a separate parameter, and a list of variables needs to keep track of whether the function is activated:
set dogenc= ... more variables
If no parameters are passed, show the help screen:
if not "%1"=="" goto params echo. echo parameters: echo. echo genc ... generate C# ... more info goto end
Parse each command line parameter:
:params if "%1"=="" goto endparams if "%1"=="genc" (set dogenc=1& shift & goto params) ... more parameters if "%1"=="all" (shift & set dogenc=1 & ... & set doall=1 & goto params) echo unknown parameter "%1" goto endend
:endparams
Add code to handle the various functions, such as checking, building, publishing, as described in the previous post.
Building Setup Projects
As msbuild does not build Setup Projects, we have to take a different approach:
"C:\path to\Microsoft Visual Studio 8\Common7\IDE\devenv" C:\path to\project.sln /build "Debug" /project C:\path to\setup.vdproj /projectconfig "Debug"
Generating Database Script
SQL Server 2000 provides a simple tool to create a SQL script with the definition of all database objects called scptxfr.
"C:\path to\Microsoft SQL Server\MSSQL\Upgrade\scptxfr" /s [server] /d [database] /p [password for sa] /f [filename] /a /h
Zip All
Finally, source code, executables, generated scripts and so on are zipped into version-specific archives using 7-zip, which can be controlled from the command line.
Summary
The batch file for my first project of this kind provides the following functionality:
- generate table triggers based on metamodel information
- generate C# constant definitions
- build executables (web, service)
- publish web applications
- build setup projects
- backup database (both as backup and as CREATE script)
- generate wiki information for developers
- generate wiki page stubs for online help
- create version-specific zip files of everything
Pingback: One Year devioblog – a Summary « devioblog
I’m curious – why don’t you just use msbuild? It’s great for command-line builds.
Pingback: Publishing Web Application Projects from the Command Line (VS2008) « devioblog
Nice article, it is help me to resolve build issues.
any full source code sample for script ?
Pingback: Stumbling Upon the “Not Pre-Compiled” Error Message | devioblog