Compiling .net projects without Visual Studio

5 August 2006
When working on my asp.net projects on the road I never had Visual Studio, so for the first time I had to look into how to compile my projects from the command line.

I started using simple batch files like this one:
%windir\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:library  /debug /reference:TweeNet.Topas.Business\bin\TweeNet.Lib.Core.dll;
TweeNet.Topas.Business\bin\TweeNet.Lib.Data.dll;
TweeNet.Topas.Business\bin\TweeNet.Lib.Web.dll;
TweeNet.Topas.Business\bin\interop.saxfilelib.dll /out:TweeNet.Topas.Business\bin\TweeNet.Topas.Business.dll /resource:TweeNet.Topas.Business\helpers\atom\mediatypes.txt
/recurse:TweeNet.Topas.Business\*.cs
Note that this is all on one line and it compiles all C# source files in a certain directory. A full description of the compiler switches is in the SDK.

I then moved on to use response files which are pretty much the same but a bit cleaner:
/target:library
/out:TweeNet.Topas.UI.Web\bin\TweeNet.Topas.Business.dll
/debug
/nologo
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Lib.Core.dll
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Lib.Data.dll
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Third.Util.dll
/recurse:TweeNet.Topas.Business\*.cs
solutioninfo.cs
put this in a text file 'biz.rsp' and then use it in another batch:
%tndndir\csc.exe @biz.rsp
This assumes I navigated into my working directory or have it in my path. Rather than hardcoding the compiler
here, I use a environment variable %tndndir  pointing to %windir\Microsoft.NET\Framework\vx.x.xxxx\. This way I can easly switch between 1.1 and 2.0 without having to change any of these batch files.

When I moved over version 2.0 of the framework, it all became easier because you can now use your Visual Studio project files as 'make' files.
With MSBuild, the new Microsoft build system you can do somthing like:
%tndndir\msbuild.exe core\TweeNet.Lib.Core.csproj /t:Build /nologo
This means you can use the same project files when at work using Visual Studio and when on the road with just the framework. Of course you need the project file in the first place. If you don't have Visual Studio 2005, they are a bit of a pain to create manually, but you can always get one of the free Express versions to do this for you.

If you are using ASP.Net it's also a good idea after building your project to compile the whole thing including the stuff in the aspx files.
%tndndir\aspnet_compiler.exe -v /topas14/ -p \www\TopasSolution\TweeNet.Topas.UI.Web

For most of my web projects I'm using the old 1.1 web project type. You can do this in Visual Studio 2005 by installing the Visual Studio 2005 Web Application Projects. Back on the road however I don't have Visual Studio and don't need to install the whole lot. Just download the msi file and extract the file 'Microsoft.WebApplication.targets' I'm using the Less MSIérables utility for this. Copy the target file onto your USB drive and use a batch file like this to copy it to the correct location:

mkdir "%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications"
copy Microsoft.WebApplication.targets "%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\"


Pages in this section

Categories

ASP.Net | Community | Development | IIS | IT Pro | Security | SQL (Server) | Tools | Web | Work on the road | Windows