I have two projects one is production code (called Main), the other is a unit test project to test the real production code (called Main.Test). Both Main and Main.Test are signed with a strong name key. To expose the internal stuff to the Main.Test project we have to add an item at the bottom of the AssemblyInfo.cs class (in Main, not Main.Test) which looks similar to this:
(Note: Names and Public Keys have been changed to protect the innocent, and semi-innocent)
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Main.Test, PublicKey=1028000004800030940000100602000000240000525341310004
Now you may be thinking to yourself: "That's great bob, but how in the hell did you get this value for the public key in the first place?"
Good question! Here is the answer:
1. Open a visual studio command prompt and enter this command:
(This is using Visual Studio 2008)
C:\Program Files\Microsoft Visual Studio 9.0\VC>sn -p "[RestOfPath]\Main.Test\MainProjectStrongNameKey.snk" "[RestOfPath]\Main.Test\MainProjectStrongNameKey.publickey"
2. You should then get a message that says "Public key written blah blah blah".
3. Now in the same command window, enter this command:
C:\Program Files\Microsoft Visual Studio 9.0\VC>sn -tp "[RestOfPath]\Main.Test\MainProjectStrongNameKey.publickey"
Now the command line should spit out the long public key, which you can then use like I did above. Now you can test your internal members in the Main project from the Main.Test project