My First project, type class library:
using System;
using Syst开发者_JS百科em.Collections.Generic;
using System.Text;
namespace Project2
{
public class Class1
{
public int num = 33;
}
}
with the command line sn -k keyPair.snk
I generate a keypair and I added keypair.snk to sign.
Second project type class library:
using System;
using System.Runtime.InteropServices;
using Project2;
namespace CSharpServer
{
[ComVisible(true)]
[Guid("DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05")]
public interface IManagedInterface
{
int PrintHi();
}
[ComVisible(true)]
[Guid("C6659361-1625-4746-931C-36014B146679")]
public class InterfaceImplementation : IManagedInterface
{
public int PrintHi()
{
Class1 obj = new Class1(); // Using first project
return obj.num; // return public int num = 33;
}
}
}
I added keypair.snk to sign.
to Use "using Project2;" in project CSharpServer I clicked "Add/Existing Project.." Project2.csproj after this I clicked in "Add Reference../Projects".
When I compiled, Generates two dlls, how to generate a single dll with the two projects?
I read about ILMerge. It seems that it combines two dll. But I have the source code, would not have a way to do this join in Visual Studio?
I read this CodeProject article that says "you can obviously just add all source files to a single project" but if my first project has 1000 classes?
I tried ilmerge: "C:\Program Files\Microsoft\ILMerge\ilmerge" /target:library /out:project.dll CSharpServer.dll Project2.dll
generate one file project.dll
Problems: if i do: regasm project.dll /tlb /codebase
... RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can ca use your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it. Types registered successfully ...
How to sign this merged dll? CSharpServer.dll is Component COM with interface and need to be registered with regasm. Project2.dll not need. Detail, I only want to register CSharpServer.dll but the project.dll contains (CSharpServer.dll + Project2.dll). And now?
I tried to sign: sn -R project.dll keyPair.snk
. Output:
Microsoft (R) .NET Framework Strong Name Utility Version 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved.
project.dll does not represent a strongly named assembly
The sign works with:
To sign, have to extract the public key:
sn -p keyPair.snk publickey.snk
I read it Giving a .NET SN
specifying and matching public key: "C:\Program Files\Microsoft\ILMerge\ilmerge" /keyfile:publickey.snk /target:library /out:project.dll CSharpServer.dll Project2.dll
After signing with the command:
sn -R project.dll keyPair.snk
Now the question is: Register this dll combined with regasm. It's like regasm only interface? what impact it?
Thanks in advanced.
You have to do that by compiling the code using csc.exe
outside visual studio and passing the command-line parameters yourself (all .cs
files).
This will be a bit tedious but can be done. Look here.
精彩评论