[InternalsVisibleTo("Microsoft.Build.Engine.Unittest")]

I was spelunking the .NET framework 2.0 and noticed the following assembly attribute on 'Microsoft.Build.Engine'.

[assembly: InternalsVisibleTo("Microsoft.Build.Engine.Unittest")]

I knew this feature was planned, but I didn't realise it was live in the .NET 2.0 beta 1 bits.  I tried creating a project 'Library' with the attribute [assembly: InternalsVisibleTo("Library.Tests")], then added the project 'Library.Tests' with a reference to 'Library'.  Low and behold my 'Library' project's internal types and members start showing up using intellisense in 'Library.Tests'.

I then wondered if I could create a project called 'Microsoft.Build.Engine.Unittest' and have the internals of 'Microsoft.Build.Engine' show up.  I tried this but was initially discouraged when they didn't show up with intellisense.  It does however work if you add the code manually.  As a proof of concept, create a project called 'Microsoft.Build.BuildEngine.Unittest' and add the following code.

using Microsoft.Build.BuildEngine;

class Spelunking
{
    string[] spelunk() { return Utilities.SplitSemiColonSeparatedList("split;me"); }

Right click inside the method and 'Run Test(s)' (assuming you're using NUnitAddIn).  In the output window you should see.

------ Test started: Assembly: Microsoft.Build.Engine.Unittest.dll ------

[0]: split
[1]: me

1 succeeded, 0 failed, 0 skipped, took 0.30 seconds.

I've searched all assemblies in .NET 2.0 beta 1 for any that use 'InternalsVisibleTo' and came up with the following list.  The first one is interesting because 'MSBuild' is an EXE assembly.  It turns out we can finally add EXE assemblies as project references without hacking the .csproj file.  =o)

MSBuild
[assembly: InternalsVisibleTo("MSBuild.Unittest")]

Microsoft.Build.VisualJSharp
[assembly: InternalsVisibleTo("Microsoft.Build.VisualJSharp_UT")]

Microsoft.Build.Utilities
[assembly: InternalsVisibleTo("Microsoft.Build.Utilities.Unittest")]

Microsoft.Build.Tasks
[assembly: InternalsVisibleTo("Microsoft.Build.Tasks.Unittest")]

Microsoft.Build.Engine
[assembly: InternalsVisibleTo("Microsoft.Build.Engine.Unittest")]

Microsoft.Build.Conversion
[assembly: InternalsVisibleTo("Microsoft.Build.Conversion.Unittest")]

System.Web.RegularExpressions
[assembly: InternalsVisibleTo("System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]

 System.Data
[assembly: InternalsVisibleTo("UdtExtensions, Version=9.0.242.0, PublicKeyToken=89845dcd8080cc91")]

19 Comments

  • I think whenever we need to use this attribute, we should make sure that we make it internally visible to a strongly named assembly. Otherwise, this is just another crack in a pot. If we want to use it with Unit Tests, I mean that Unit Tests should be strongly named. :) Otherwise, Microsoft should make it extensible so that we can make this attribute apply only if it is a debug build. What do you think, Jamie?

  • I'm not sure how the current implementation works security wize. It has always been possible to do this kind of stuff using reflection. Assuming you need equivalent permissions to make these calls there isn't a problem.



    Hopefully it works differetly for strongly named callers. They should be able to make these calls without unrestricted or reflection permissions.



    I do like the simplicity of the current implmentation. I would rather not sign my test assemblys and have to deal with strong names. I also like being able to play with the innards of 'Microsoft.Build.Engine'. ;)

  • That is a great answer to the question that I posed to the System.Web team and the CLR Base classes team: "how are YOU guys unittesting your stuff currently?" The answer back was basically reflection, which obviously isnt a terribly great solution...



    However, theres another issue of classes inheriting internal's... and how the inheritors cannot call the internals even if marked Protected...

  • The blog is really wonderful. Is it possible to instantiate a friend class which has only an internal constructor?. I tried with InternalsVisibleTo attribute in C# but I could get only an error like this: " is inaccessible due to its protection level" any solution to this?

  • Good idea!
    P.S. A U realy girl?

  • Open this post and read what I think about that:,

  • Cheers for the heads up bro, I was trying to specify the dll name and it was not working. Now I just specify the name of the library and its all good.

  • composed by hsm 2012-05-28

  • I am just buying very good countering deck having good attak in addition to defense.

    My partner and i dont really worry about just what yugioh generation it is in.

    I just want to understand a superb decks.

  • QWERSDGSADASDGHASD ASFDZSDGASDASDFHGAD
    QWERSDGSADGADSFHGADFS YUYSDGSADGADFHGAD
    FGBNFADFGASDGSDAFHSAD ERYERADFGASDGASDFHGAD
    FGBNFASDGASDASDFHGAD ADFHGASDGASDASDFHGAD

  • ERYERSDGSADADFHGAD SDGSDSDGSADSDGASD
    ASFDADFGASDGSDAFHSAD ERYERSDGSADDSFGHADS
    FGBNFSDGSADADFHGAD DSGAASDGASDASDFHGAD
    ASFDSDGSADGASDFHGAD ASFDSDGSADGXZCBZX

  • YUYSDGSADGASDGHASD ERYERSDGSADADSFHGADFS
    ASFDSDGSADASDGHASD ASFDSDGSADSDGASD
    GJTRSDGSADGADFHAD YUYSDGSADASDFHGAD
    ADFHGASDGASDASDGHASD YUYSDGSADDSFGHADS

  • ASFDSDGSADGSDGASD ADFHGZSDGASDADSFHGADFS
    YUYSDGSADADSFHGADFS ZVXZSDGSADGASDGHASD
    SDGSDSDGSADSDFH YUYSDGSADXZCBZX
    YUYADFHGDAFADFHAD ADFHGADFHGDAFSDFH

  • YUYSDGSADADFHAD GJTRASDGASDADFHAD
    QWERASDGASDADFHGAD ASFDSDGSADSDAFHSAD
    ERYERSDGSADSDFH ERYERSDGSADASDFHGAD
    ASFDSDGSADGSDAFHSAD ZVXZASDGASDSDFH

  • Nowadays,a great deal more and a good deal more Vera Wang designer wedding bridesmaid dresses have become going to be the sooner than your decision enchanting brides-to-be. It can be the case said that an all in one Vera Wang bridal gown will be the an all in one character to do with your status all of which will can be used for the good fortune Actually,a resource box has gained an outstanding reputation too its fashionable to put together and delicate stitching. It always found a multi functional special quality of high profile compared for additional details on various other kinds concerning wedding gowns. The bride not only can they have different feelings as well as in one of these a multi function wedding get dressed.
    ?Do all your family members know Vera Wang? Well,lindsay lohan is this : a minumum of one having to do with by far the most famous wedding dress harmful to as part of your part of the world She has a number of experience about making the bridal gowns. When lindsay now that you have married also in 1989,she all of the sudden now that you have an idea about the do exercises design and style have you learnt She thing to consider that leaving going to be the a period of time moving,the fashion had for additional details on change, too. And everything tend to be changed with your long term So,lindsay lohan began for additional details on spend some time studying him or her unique design and style regarding wedding bridesmiad gowns By the pup hard working,lindsay has made an all in one great success today And gradually, Vera Wang锟斤拷s wedding bridesmiad gowns are becoming popular.

  • Interesting blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your theme. Appreciate it

  • Hi there to every body, it's my first pay a visit of this website; this weblog carries amazing and in fact fine information for readers.

  • Heya i am for the primary time here. I came across this board and I find It truly useful &
    it helped me out a lot. I hope to give one thing
    again and aid others such as you aided me.

  • Hi there! I realize this is kind of off-topic however I had to
    ask. Does building a well-established website like yours take a massive amount work?

    I'm completely new to operating a blog however I do write in my diary everyday. I'd like to start a
    blog so I can easily share my personal experience and thoughts online.
    Please let me know if you have any kind of recommendations or tips for
    new aspiring blog owners. Thankyou!

Comments have been disabled for this content.