Creating and Using Multifile Assemblies
page 3 of 7
by J. Ambrose Little
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 33372/ 90

So How Do I Do It?

If you've come this far, you're likely rapping your fingers on the table, wondering when I'll get to the example.  Good news!  You've arrived at the right place.  As mentioned, I created three projects in VS.NET, though having them as projects is really unecessary, since neither VB.NET nor Visual C# give you the option to compile as modules, which is what you need to do for a multifile assembly.  The main reason I used projects is for the nice editing environment and logical grouping.  It also leaves the option open to easily build them separately as assemblies in their own right.

We'll ignore the details of the code, as that is not particularly pertinent.  Suffice it to say that I used a sample cryptography class in my C# project (feel free to grab it and use it in your own projects), and I created an extremely simple class in my VB project that makes use of the VisualBasic.DateDiff function.  (As an aside: Please note that, despite common misconceptions, you can easily use the Microsoft.VisualBasic namespace in C# as well--it's a .NET assembly just like the rest of them--so don't let the name mislead you.  I only used it here on a whim because I could not think of anything else I would want to do in VB.NET that I wouldn't prefer to do in C#.  In general, I recommend C# over VB.NET for code libraries due to C#'s inherently supported Intellisense and documentation via XML comments.)  The third project is a tester project that references the assembly created from the other two projects and uses methods from each to demonstrate that the example works as expected.

The real core of the sample is in the build scripts I have created.  You will notice, if you download the sample, that there are several files in the solution directory that enable us to easily build the multifile assembly.  Remember, you cannot do this in VS.NET (2002 or 2003), which is why we must have build scripts.  I have created two batch files, BuildWithAL.bat and BuildWithCSC.bat, to demonstrate two different ways that you can create a multifile assembly.  BuildWithAL.bat builds both the VB.NET and C# projects as modules and then links them together using the Assembly Linker (al.exe), producing an assembly of three files--the two modules and the assembly manifest.  BuildWithCSC.bat builds the VB.NET project as a module and then uses the C# Compiler (csc.exe) to create the assembly by incorporating the VB.NET module with the /addmodule compiler switch.

In both cases, you will note that the C# project has the AssemblyInfo.cs file, which contains the desired assembly attributes for the assembly.  Most of these can also be specified on the command line using the compilers and the Assembly Linker, but I chose the file for conceptual and physical grouping of the assembly attributes, such as title, description, version, key file, etc.


View Entire Article

User Comments

Title: very good article and explanantion   
Name: Jon
Date: 2005-08-12 12:18:56 AM
I don't use Visual Studio for .net development, so this is excellent information for my work.

Title: fd   
Name: sp
Date: 2005-07-06 7:08:13 AM
Title: Good quick explanation of the al   
Name: Tom
Date: 2004-09-28 1:06:37 PM
I was looking for a quick explanation of the assembly linker and I found this through a search on the web. It was concise and well written. Thanks.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-23 5:28:02 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search