Visual Studio 2005 has a built-in Publish command which generates a set of (more or less) randomly named DLLs, instead of a single DLL that was generated back in the good old days of ASP.Net 1.1.
The publishing of an application usually always takes the same steps with the same options, and can take a couple of minutes (depending on your project). Since repetitive tasks are a source for errors, I wanted to automate this procedure.
I wanted to take a look under the hood and create a batch file which compiles a web application from source files using aspnet_compiler and then calls aspnet_merge.
The first problem I met was that aspnet_merge was not in the PATH. Rather it is being installed into
which is a localized path, so you either change the PATH variable, or copy aspnet_merge into a directory in the PATH.
I created a batch file called publish.cmd, which looks like this:
if "%1"=="" goto errnoparam if not exist c:\inetpub\wwwroot\%1\nul goto errnotfound setlocal call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 echo on set base=c:\archive\publish\%1 if not exist %base%\nul md %base% rd /s /q %base% echo compiling to %base% aspnet_compiler -v /%1 -f -d %base% aspnet_merge %base% -w %1 -debug endlocal echo web compiled to %base% goto end :errnoparam echo usage: %0 web goto end :errnotfound echo web %1 not found goto end :end
First, the script checks whether the name for the web application is provided, and whether it is a valid existing name. Next, the VS2005 environment variables are initialized.
Finally it calculates the name of the output directory, and invokes aspnet_compiler and aspnet_merge.
- beautifully named DLL files
- empty .aspx and .ascx files (so nobody steals your markup😉 )
- ugly .compiled files in the bin directory (cannot be deleted without breaking the application)