ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
Professional C# (2nd Edition)
Professional C# (2nd Edition)

Find Prices
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software
Click here to return to my article index

Command Line Compiling in .NET

A command line compiler is something that many of today's Microsoft centric developers have never had to deal with. Many of us have only developed Windows applications with Visual Basic. It is not possible to compile a Visual Basic 6 (and lowe) application/component using the command line - you are restricted to the IDE. Well, the .NET Framework has changed all of that. We now have a command line compiler for both C# (csc.exe), VB.NET (vbc.exe), and most likely any new language that is ported to .NET. The idea of compiling an application at the command line is something that many developers detest. However, there developers among us that relish in the quick and powerful capabilities of a command line compiler. This article will give examples of how to use the VB.NET compiler but many of the terms/ideas can be applied to the C# compiler as well.

Typically, we will use the command line compiler to create an assembly (definition below).
What is an assembly? - From Remas article - "An assembly forms a logical unit of functionality. It is the fundamental, self-describing unit of deployment, version control, reuse, activation scoping, and security permissions. It contains the assembly manifest, which represents all the metadata needed to specify the version requirements, security identity, and other information."

There are three types of assemblies - single file, multiple file, and library. This article will focus on creating single file and library assemblies.

The library assembly is an assembly without a main entry point (ie there is no main or winmain function). Library assemblies are used when developing ASP.NET pages with code behind files. There was a question on one of the lists at http://aspalliance.com/lists recently that read something like, "How do I compile the .vb file for one of the quickstart samples?". So, here is an example that demonstrates how to compile a .vb code behind file.

vbc /t:library /out:bin/myLibraryAssembly.dll  myCodeBehindFile.vb
Let's dissect this command line:
'vbc' is the name of the VB.NET compiler executable
'/t:library' tells the compiler we want a library assembly
'/out:bin/myLibraryAssembly.dll' tells the compiler we want the library in a .dll called myLibraryAssembly.dll and to place the dll in the bin folder
'myCodeBehindFile.vb' is the code behind file that we want compiled

What if we wanted to create an single file (executable) assembly from a VB.NET code module?
Well, we could create a single file assembly (or multiple file assembly). The syntax for creating a single file assembly isn't that much different from the syntax to create a library assembly. When creating a single file assembly, we can decide the name of the executable or we can use the compiler default (same name as the code module). Here is an example that specifies the name of the executable:
vbc /out:mySingleFileAssembly.exe  myCodeBehindFile.vb
Notice we didn't include the '/t:library' switch because we are creating a single file (executable) assembly - not a library assembly. Also, a single file assembly must have an entry point. If you want to use the default assembly name then simply remove the '/out:mySingleFileAssembly.exe' switch.

Well, I hope this article has given you a jumpstart into the world of command line compiling in .NET. For more information on Assemblies check out Remas article Using .NET Components in ASP.NET".


Click here to return to my article index
 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 2/9/2010 2:25:03 PM