问题
I have two assemblies. One assembly is referring to the another one. I checked the manifest of first assembly and found it is referencing to the second one with some specific token key.
But I checked the token of second assembly and found that it has a different public token. So somehow I missed the correct second assembly. So I want to know is there a way I can change the second assembly's public token to the one which first assembly needs.
Also I have another second assembly also which has public token = null.
回答1:
Sounds like you want to rebuild the second assembly and sign it with a different key, which would be easy if you had the source so I guess you don't?
I think it would be easier to rebuild the first assembly so that it references the second assembly you have, using the public key token that is present on the second assembly. Easier, but not entirely straightforward.
I think you should be able to achieve it by running the first assembly through ildasm.exe
, change the public key token on the reference to the second assembly, and then run the result through ilasm.exe
, to produce a new version of the first assembly.
A rough outline of the steps involved...
- Run
ildasm.exe /out=first.il first.dll
(orfirst.exe
) - Edit
first.il
and find the .assembly extern block for the reference tosecond.dll
- Change the public key token in that block
- Run
ilasm.exe first.il
to producefirst.dll
(orfirst.exe
)
Be warned, I haven't used these tools for a long time, and never to manipulate public key tokens in this way, so you will probably have to add some ingenuity of your own. But on the other hand, I can't think of a reason for this approach not to work.
回答2:
You are asking "how can I forge second assembly's signature to make first assembly think it's original". Unless you have a keypair, used to sign the "right" assembly, you can't. So the best approach is to ask the vendor of the assemblies to provide a correct pair.
回答3:
From my personal experience you may want to change your app .Net framework so it will match dlls.
来源:https://stackoverflow.com/questions/3889124/how-to-change-the-public-token-of-the-assembly