For testing, I often use the InternalsVisibleTo for my unit tests. It looks like this:
[assembly: InternalsVisibleTo("MyProject.Domain.Tests")]
When the assembly is strongly typed, though, this simple statement will not work, and we get the following message:
Error: "Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations"
To fix this, you must do two things: You must sign the test assembly, and you must include the public key in the InternalsVisibleTo statement.
To get the public key value from the .snk file, use the sn.exe utility included in the .NET SDK. You must do two things, first, create a .snk file that contains only the public key:
sn -p MyKey.snk MyKey.PublicKeyOnly.snk
Then, you can extract the public key value with this command:
sn -tp MyKey.PublicKeyOnly.snk
This will produce a similar output:
Public key is
0024000004800000940000000602000000240000525341310004000001000100cfb8bc23b86a08
e70d021dd53d3b0293e716e71015870bdcc58a0231a4228618851a83e06077f5a44f42beb2baf3
56ad2d344521a96b0081ed0f25f9227523e3625eda524efe1cf2e1e5e41f3693a76ec52347684b
8129a4bb2d5fc49681adf33da0eecc4f81f011af4539d12abe1b4e760b5ce32d766db1012d4402
8381f0b4
Public key token is 2ff2b71993eeff95
Copy the public key value and update the InternalsVisibleTo:
[assembly: InternalsVisibleTo("MyProject.Domain.Tests, PublicKey=
0024000004800000940000000602000000240000525341310004000001000100cfb8bc23b86a08
e70d021dd53d3b0293e716e71015870bdcc58a0231a4228618851a83e06077f5a44f42beb2baf3
56ad2d344521a96b0081ed0f25f9227523e3625eda524efe1cf2e1e5e41f3693a76ec52347684b
8129a4bb2d5fc49681adf33da0eecc4f81f011af4539d12abe1b4e760b5ce32d766db1012d4402
8381f0b4")]
Voila! You can now access the internals from your test project for strong named assemblies.