PowerShell and (not) parsing command lines

Wednesday, 22 July 2015

A short reminder note for myself.

To tell PowerShell to not parse the remainder of a line, use --%. This is invaluable when calling out to external commands and you don’t want to escape every special character with a backtick (`).

So instead of this:

icacls X:\VMS /grant Dom\HVAdmin:`(CI`)`(OI`)F

You can write this:

icacls X:\VMS --% /grant Dom\HVAdmin:(CI)(OI)F

See the Stop Parsing section in Online Help for more info.

Glimpse and Castle Windsor

Monday, 20 July 2015

Some breaking news in the last week – Microsoft has taken over the sponsorship of Glimpse – an open source diagnostic platform for web applications. Glimpse has been described as the server-side equivalent of your browser’s F12 Developer Tools, so it’s great that first Red Gate and now Microsoft have recognised the value of this tool and supported its development.

I’ve been making use of Glimpse recently to get some more insight into the timing of server-side code. It hooks into the ASP.NET pipeline and gives a useful breakdown of various activities. Depending on what you’re using with your web application, there’s extra extensions that you can add to glean more information – like Web Forms, Entity Framework etc.

Even for things like an Inversion of Control Container can provide interesting data. There’s already extensions for AutoFac and Ninject, but not for Castle Windsor – one of my preferred IoC containers.

I know that there are quite extensive diagnostics provided by Castle’s container – but usually you only see these when you’re debugging, so I thought it might be possible to expose the same information to Glimpse.

And so I created the Glimpse.Castle extension.

It adds a new tab to to the Glimpse dashboard with all that useful detail from the Castle container’s diagnostics service.

Web browser showing Glimpse dashboard

The extension source code is on Github and currently you can build it and run with the latest release of Glimpse. When I get a chance I’ll get it published on NuGet and get it added to the extensions page on the Glimpse website.

Visual Studio 2015 Launch

Saturday, 18 July 2015

Set your alarm clocks because the Visual Studio 2015 launch begins at 20th July 2015 15:30 UTC. (That’s 1am Tuesday morning if you live in Adelaide).

Or you can enjoy a good night’s sleep and watch the recordings on Channel 9 at a more sensible time Smile.

Either way, I’m definitely looking forward to the final RTM of VS 2015 – I’ve been using the Release Candidate version on and off over the last month or two and there’s definitely some nice enhancements.

Speaking at DDD Melbourne 6

Saturday, 20 June 2015

I’m excited to confirm that I’ve had a talk accepted for DDD Melbourne, a one day developer conference to be held on Saturday 8th August, in yes, Melbourne Smile(flights are booked!)

My “10+ unusual tips & tricks for .NET” presentation (previously featured online and at last week’s ADNUG meeting) is listed as one of the last sessions of the day before the closing locknote. ADNUG attendees will be able to confirm that I do indeed have more than 10 tips.

The agenda is now live - http://dddmelbourne.com/agenda

If you’d like to attend, you’ll want to set an alarm for 29th June at 12:30+0900 – as that’s when tickets go on sale. Last year they sold out in just 12 hours, so I wouldn’t be surprised if they go even quicker this time.

It should be a great event, and I’m really looking forward to being a (small) part of it.

Finding missing files in Visual Studio

Monday, 15 June 2015

A project in Visual Studio is used to indicate which files on disk should be used to build something. For a C# project, it will indicate the .cs files that should be compiled.

It is possible to have a file on disk that isn’t included in the project (the file is just ignored), and conversely it is possible to have a file reference in the project that refers to a file that doesn’t exist on disk. In this latter scenario, if it is a compilable (.cs) file then the C# compiler will issue an error that it can’t find the file. But if it is another kind of file (like a .jpg, .png or .css for example), the compiler just ignores it and you won’t get any errors.

If you didn’t realise that there are some missing files, then the first time you might actually realise this is when either you go to package the application for deployment (when the packaging step could fail), or when you run the application and some functionality is broken.

Here’s a Solution opened in Visual Studio. I can tell you there are actually two files that are missing, but there’s no clue as to where they might be.

Visual Studio Solution Explorer, with projects collapsed

Missing files are identified by a slightly different icon with a yellow ‘warning’ triangle in the Solution Explorer, but that’s only helpful if you’re actually looking at the right place (not always easy if you have lots of projects with a deep folder hierarchy). If we expand the first folder out, then we can see the first missing file.

Visual Studio Solution Explorer, with first project expanded

But there’s still another one we haven’t found. If you don’t go looking for it, you probably won’t notice it. So to help identify missing files as soon as possible, I’ve created a new Visual Studio extension – Show Missing Files.

After you do a build, the extension scans all the projects you have loaded in Visual Studio and generates errors for any files that are referenced but don’t actually exist. Here’s the Error List window for our sample solution after doing a build:

Visual Studio Error List, with two missing file errors

The two missing files are listed, along with the projects that reference them. You can then double-click on one of the errors and it will take you directly to the file reference in the Solution Explorer.

Visual Studio Solution Explorer with second missing file highlighted

And there it is! You can now fix the missing reference (eg. remove it, or restore the missing file back on disk).

Show Missing Files is available for Visual Studio 2013 and 2015. Try it out today in the Visual Studio Gallery or search for “Show Missing Files” in the Visual Studio Extensions and Updates dialog.

Don’t forget to give it a few votes in the gallery. The source code is available at https://github.com/flcdrg/VsShowMissing. All contributions welcome!