Compartilhar via


New InternalsVisibleTo attribute in .NET 2.0

I discovered a cool new attribute in .NET 2.0 called "InternalsVisibleTo". This takes an assembly name and public key token and grants it access to the assembly internals.

One cool application I can think of is that you no longer have to place your unit tests inside the assembly they are testing; instead you can aggregate them into an external assembly and keep the production binaries as small as possible. Of course you can always wrap the tests with compiler directives, but I think that the former approach would be quite useful in many instances.

Check System.Deployment.dll to see an example of this:

[assembly: InternalsVisibleTo("dfsvc, PublicKeyToken=b03f5f7f11d50a3a")]