Nov 5 2015

Claning VisualStudio build files with PowerShell

Category: PowerShell | Visual Studio — Duke @ 09:23

These days i've starting using PowerShell, it is a pleasure!

it is a long time that i want to learn PowerShell and finally i've found some occasion to give it a try.

It is like a drug, i can't stop using it!


despite the fact that my company have lent to me a new laptop, a shiny i5 with SSD disk, this new hardware has a 128GB disk, that it is ok for the OS only in these days.

Considering that my phone has 32 and my next one probably 128... basically i'm doing my company business by phone :(

ok stop ranting and let's go to the point.

i've to clean all the cap that VisualStudio 2010 produces when compiles.

I've a big solution with 70+ projects, belive me or not, the amount of DLL plus OBJ and pdb it produces it is more or less 400Mb some day more some day less


then i've created this nice script

dir -Recurse -Attributes Directory |`
 where -Property Name -ne 'Packages' |`
 dir -Recurse -Attributes Directory |`
 where {($_.Name -match 'bin') -or ($_.Name -match 'obj')} |`
 remove-item -Recurse -force

dir -Recurse -Attributes Directory |`
 where -Property Name -eq 'TestResults' |`
 remove-item -Recurse -force

basically it starts from the root you launch it in and search for all the BIN or OBJ folder not under packages (in great respect of nuget) and delete the entire hierarchy under BIN and OBJ

it frees up a lot of space and it took me 5 minutes to write it.





Jul 24 2013

Null safe accessor

Category: C# | Visual Studio — Duke @ 06:54

It is happened to me many time to have to accesso a long hierarchi of object just to display a value to the user, and possibly this hierarchy contains null values

So the case is a.B.C.D.E.F where a is my object reference B, C, D, E are child of a in a long hierarchy of property accessor, and finally F is a simple integer o a string that i don't care about but the user want to see (if present)


It turns out that some languages have the so called  Groovy's safe dereferencing operator  (see

but C# have not :(


Stack overwlow is full of smart solutions, some very elegant (see some here but allof these are in someway suboptimal


the one i like more is


bossName =Employee.NullSafe( e => e.Supervisor).NullSafe( s => s.Boss).NullSafe( b => b.Name);


but is too verbose :(


so i've ended up with an alternate solution (that cames in two flavours to tell the true)



Sep 22 2011

Visual Studio 2010 Expression Tree Debugger Visualizer: how to make it work.

Category: C# | Visual Studio — Duke @ 19:21

I’m developing a quite complicated (it is always complicated when you have to manage big trees) project.

As in the project there are a lot of trees that are moving around (never seen a tree walking down the streets?)  and transforming themselves I’ve thought that it could be nice to use a Debug Visualizer to have a clearer view of the structure of these expression trees.

I know, the visual studio 2010 have the new DebugView property that makes it inspect the tree.. but it is still complicated to read when you have kilometric long namespace names that ends in generic object that in turn uses generic parameters with (again) long names.

it is a mess Triste

so I’ve decided to use the old but still good Expression tree visualizer available from the Visual studio 2008 C# code samples.

Downloaded, changed the reference to the Microsoft.VisualStudio.DebuggerVisualizers.dll library so to reference the newest one (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.DebuggerVisualizers.dll) and then compiled.

But here starts the problem:

My configuration is Windows 7 64 bit Ultimate and Visual studio 2010 Ultimate (with latest service packs and everything)

My projects are all in .Net 4.0 at the moment I'm writing.

I’ve compiled the visualizer, put it in the right folder

C:\Users\Duke\Documents\Visual Studio 2010\Visualizers

and BAM! …. nothing Triste

nothing appear, no magnifier  when I hover an expression reference.

I’ve tried to moving the visualizer in all the possible valid location (also considering the 64 bit architecture) but noting!

Binged and Googled… I’ve found that many people have had the same issue.

So I’ve started looking inside the actual code, and here it is!


[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeVisualizerObjectSource), Target = typeof(Expression), Description = "Expression Tree Visualizer")]

Sooooo wrong! I’ve fixed it this way


[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeVisualizerObjectSource), Target = typeof(Expression<>), Description = "Expression Tree Visualizer")]

Note typeof(Expression) transformed in typeof(Expression<>)

The type to visualize should be the generic one to work with the last version of the framework.

Recompiled, dropped in the right folder and this time IT WORKS!

Ok! now it works like a charm I hope this could help also other people with the same issue Sorriso