Linking Assemblies at Compile Time

Posts   
 
    
Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 04-Aug-2004 17:45:06   

A bit of an off topic question here:

Has anyone come across a way of linking separate assemblies together into a single assembly at compile time?

I'm remembering back to my C days and if memory serves me correctly, I could build object code and then at the last minute bind these compiled modules into a single executable.

The trouble is, I have a habit of building a separate project for each of my major namespaces, but don’t want to deploy 50+ DLLs in the final released application. The main reason for this is security / performance: I don’t want to have to implement Code Access Security between each DLL as this would prove inefficient.

LLBLGen's Data layer is an example of where I don't want third parties to be able to reference my database by simply referencing my assembly.

[aside]

Frans, have you thought about including any CAS / Strong Naming in the generated code projects? I hate the idea of touching generated code...

[/aside]

I would love to be able tell the C# compiler "Make me a single DLL by linking all these DLLs together".

The only way I can see to achieve this is to build a separate project which references all the C# code files and builds the entire lot into 1 assembly. I really don’t like this idea as the 2 project are bound to get out of sync in no time.

Any thoughts?

Marcus

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 04-Aug-2004 17:53:11   

Marcus wrote:

A bit of an off topic question here:

Has anyone come across a way of linking separate assemblies together into a single assembly at compile time?

You can compile to 'modules' which you can include into 1 assembly. The catch: you can only do this on teh command line. VS.NET doesn't support this.

[aside]

Frans, have you thought about including any CAS / Strong Naming in the generated code projects? I hate the idea of touching generated code...

[/aside]

The assemblyinfo.cs file isn't overwritten anymore once it is generated. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 04-Aug-2004 17:56:18   

Otis wrote:

You can compile to 'modules' which you can include into 1 assembly. The catch: you can only do this on teh command line. VS.NET doesn't support this.

I thought there might be a way! I'd better dig out the SDK docs... Cheers!

The assemblyinfo.cs file isn't overwritten anymore once it is generated. simple_smile

Great smile

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 05-Aug-2004 05:55:43   

Another way:

use the StrongNameIdentityPermissionAttribute at the Assembly level to stop all assemblies from loading the signed assembly unless the loaders are signed with the same key AND / OR use the StrongNameIdentityPermissionAttribute at the Type or Member level to ensure that callers are signed by the same key.

Here is the assembly info for MyAssembly.dll:


[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"..\..\..\EDS_Key.snk")]
[assembly: AssemblyKeyName("")]
[assembly: StrongNameIdentityPermissionAttribute(SecurityAction.RequestMinimum, 
PublicKey=MyAssembly.Constants.PublicKey)]

Here is a type, defined in MyAssembly.dll:


using System;

namespace MyAssembly
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class Constants
    {
        public const string PublicKey = "0024000004800000940000000602000000240000525341310004000001000100cbc86502ac31a6" +
            "79f3b71e594bc5aca7cbde3cdcca074ee0c791a41cf3cc61e1a8770cb9d35e8b01b60885d5501e" +
            "b7353440f7be071ee891c1e37064513e37aaf9da76930085b636795ef6ad1cf601203702083540" + 
            "a184f60537830ab059b471c5a0949b8d4f1512a30900a061364dca82fbd4c2e8df3f658b412ac0" +
            "e40bdaa8";

        private Constants()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}

And here is the assemblyinfo for an assembly called MySignedAssembly that references MyAssembly:


[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"..\..\..\EDS_Key.snk")]
[assembly: AssemblyKeyName("")]
[assembly: StrongNameIdentityPermissionAttribute(SecurityAction.RequestMinimum, 
PublicKey=MyAssembly.Constants.PublicKey)]

And lastly here is a type in MySignedAssembly that is protected from unsigned callers:


using System;
using System.Security;
using System.Security.Permissions;

namespace MySignedAssembly
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    [StrongNameIdentityPermissionAttribute(SecurityAction.LinkDemand,PublicKey=MyAssembly.Constants.PublicKey)]
    public class Class1 
    {
        public Class1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static System.DateTime CurrentDate()
        {
            return System.DateTime.Now;
        }
    }
}

Hope this helps