How to register a non-strong-name assembly to be l

2019-01-24 16:51发布

问题:

One of our partners provided us with an assembly we need to access from our application. Unfortunately, this is not strong-name so we can't install it to the GAC. And we can't place it in the same place as our executable.

Is there a solution for this?

EDIT: This will be a temporary solution only for testing, when they go RC, we will have a strong-named assembly.

回答1:

You have a few options at that point.

The first is to place the assembly in a directory that has the name of the assembly (without the extension) which is a subdirectory of the application directory.

The second is to specify the sub directory you want the CLR to probe for references in the app.config file using the probing element.

Finally, you can load the assembly dynamically using the various Load methods on the Assembly class but I would say that's a very bad idea in this case, given that you have the assembly, and you have concrete types that you want to use in it. Late time assembly loading like this is typically used when you want to subsitute the implementation of certain abstractions, which doesn't seem to be the case here.



回答2:

Workaround using decompilation & signing (using Developer Command prompt for Visual studio):

ildasm.exe /all /typelist /out=DataSystem.il DataSystem.dll
ilasm.exe /dll /optimize /key=DataSystem.snk DataSystem.il

DataSystem.snk can be generated as a file using Visual Studio IDE http://www.bloggedbychris.com/2011/09/29/signing-a-net-assembly-in-visual-studio/

then you should be able to run

gacutil.exe -i DataSystem.dll


回答3:

Yet another solution is to add the following to the machine.config file:

<runtime>
  <developmentMode developerInstallation="true"/>  
</runtime>

And add DEVPATH = path to the system environment variables.



标签: .net gac fusion