Home All Groups Group Topic Archive Search About

Using AL.exe to link modules into assembly

Author
18 Feb 2005 3:39 PM
scayze

Hello all,

I'm writing a program that first uses csc.exe to compile C# files into
a netmodule, which works fine. The resulting fileis 72 KB in size. Next
it uses al.exe to link the netmodule to an assembly and add strong
naming and resources. Below is a simplified example of the command I
use:

al /keyfile:myKey.snk /version:1.0.* /embed:myResource.resx /t:lib
/out:myDLL.dll myModule.netmodule

I was wanting the result to be a strong-named assembly with all the
contents of the netmodule, plus resources. Instead, the assembly
generated is 5 KB in size. When I use ildasm.exe to analyze the
assembly and it's manifest, there are just external references to types
that refer to the .netmodule, but no actual type information.

I know about other tools such as sn.exe for strong naming and dynamic
assemblies to emit the information, but I just don't know the best
approach. Can anyone tell me how to take a module and add strong naming
and resources to it? Or, how does Visual Studio do it?

Thanks in advance,
Shannon
Author
18 Feb 2005 5:24 PM
Mattias Sjögren
>Can anyone tell me how to take a module and add strong naming
>and resources to it?

I don't understand why you're compiling to a module to begin with
instead of an assembly. The C# compiler can handle both strong naming
(use the AssemblyKeyFile attribute) and embedding resources (the /res
option).



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Are all your drivers up to date? click for free checkup

Author
18 Feb 2005 6:07 PM
Shannon Cayze
Hi Mattias,

Thank you for the quick response. In the last few minutes I discovered
this myself. My original problem came from the fact that the
AssemblyKeyFile attribute is stored in AssemblyInfo.cs. The way I would
declare this is as follows:

[assembly: AssemblyKeyFile(MyAssembly.snk")]

When compiling in Visual Studio, it knew to get the .snk file from the
obj\Debug directory. However, when I compiled it using ICodeCompiler,
the compiler didn't know where to locate it. Therefore, I tried ignoring
AssemblyInfo.cs when compiling, and adding the key later with the al.exe
/keyfile option. Recently I found that if I change the
AssemblyKeyFileAttribute to the following, it would locate the .snk file
in both Visual Studio and ICodeCompiler.

[assembly: AssemblyKeyFile(@"..\..\obj\Debug\MyAssembly.snk")]

Now I can compile AssemblyInfo.cs with ICodeCompiler and use the
/resource option to specify my resources. Everything seems to be working
fine.

I do have one question. Is embedding resources this way the same as
using the EmbeddedResource compile option for the file in Visual Studio?

Thank you for taking the time to respond.
Shannon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Author
18 Feb 2005 10:05 PM
Mattias Sjögren
Shannon,

>I do have one question. Is embedding resources this way the same as
>using the EmbeddedResource compile option for the file in Visual Studio?

Yes. Except perhaps that VS adds the namespace to the resource name,
I'm not sure if ICodeCompiler does that (I know the command line
compiler doesn't).



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
22 Feb 2005 3:59 PM
scayze
Hi Mattias,

> Yes. Except perhaps that VS adds the namespace to the resource name,
> I'm not sure if ICodeCompiler does that (I know the command line
> compiler doesn't).

ICodeCompiler behaves like csc.exe and does not include the namespace.
As you suggested, VS does. Thanks for all your help.

Shannon

Bookmark and Share