Using AL.exe to link modules into assembly

S

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
 
M

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
 
S

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
 
M

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
 
S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top