Blog Moved ....

ScottCate.com

community

frenz

my book(s)

my products

How do you setup a family of .net assemblies that can see each others internals?

I've always put my unit tests in a separate assembly/project, so they don't mingle with shipped production code (although I've read that some like to ship the test for debugging purposes). So let's say I have ProjectA.DLL in it is a class.

internal class DoSomethingSecret {} How do you write a test for that in ProjectA.Test.DLL? I think the answer also involves my next (and the real) question.

Since I started programming in .net, I've not like the public keyword. It just seems so open to the world; but it's been my only gateway for communicating across my own assemblies. I know there is a way to setup a group of (signed??) assemblies as a family, but I don't know how to do it. In this scenario (I'm guessing/hoping), each family member (assembly) can see the internal methods of their relatives?

With this solution, I'll be able to have a group of assemblies that can see the internal methods of each other, and I can mark most of the classes, methods internal. And the only markings of public, are truly items/signatures that I want to expose to the world.

Thanks for your pointers.

[UPDATE :: Solution]
Thanks for the quick comments. This article by Matthew Cochran offers the perfect solution.

Posted: Jul 19 2007, 09:55 AM by scott cate | with 6 comment(s)
Filed under: ,

Comments

Guy Burstein said:

Hi

You can use the [assembly: InternalsVisibleTo(...)] attribute.

Follow this link:

www.dotnetfun.com/.../WhatsNew20FriendAssemblies.aspx

Guy Burstein

blogs.microsoft.co.il/.../bursteg

# July 19, 2007 12:14 PM

Matt Berther said:

How about the InternalsVisibleTo attribute?

# July 19, 2007 12:16 PM

Scott Cate said:

I was just pointed to the "InternalsVisibleToAttribute" which I'm now investigating, and seems like the perfect answer.

# July 19, 2007 12:23 PM

Matt Kellogg said:

A quick Google search turned up this: www.almostserio.us/.../using-internals-across-assemblies

Basically, mark your assemblies with the InternalsVisibleTo attribute. You just specify the other assembly which can view it. This I assume only works down to the internal level and not the protected or private level.

# July 19, 2007 12:33 PM

cibrax said:

Hi Scott, you can use friendly assemblies for that. Take a look at an example here, www.c-sharpcorner.com/.../reuse.aspx

# July 19, 2007 12:48 PM

Joe said:

This might be of some help.  I have seen it used with nUnit.

msdn2.microsoft.com/.../system.runtime.compilerservices.internalsvisibletoattribute.aspx

# July 19, 2007 12:56 PM