Sunday, 10 July 2016

The changing state of installers

I’ve begun to notice that there’s somewhat of a gradual move away from MSI-style installers. This is an interesting change considering for a number of years now I’ve been a keen proponent of creating an MSI to package up your software and drive the installation process during deployment.

MSI (Windows Installer – previously Microsoft Installer) started life as the Office 2000 installer. Office was (and still is) quite a large and complex piece of software and I guess the development team realised they needed a slightly more reliable way to install all the bits in the right places.

This then evolved into a more general-purpose installer technology and was finally built right in to Windows itself as the preferred way to install applications and services.

So what’s changed?

MSI is great if you just need to install a single instance of an application. It is possible to handle multiple instances – for example SQL Server. If you’ve ever installed SQL you’ll know that you can use the setup program to install multiple instance of SQL Server. I recently learned through a question posed to a Reddit AMA that they use ‘Transforms’ for this. It is possible, but not super easy.

Then there’s Nano – Nano Server to be precise. This is the new super cut-down, minimalist edition of Windows Server, and one of the things that has been left out to keep it as lean as possible is MSI support. To build software for Nano, you’ll be packaging it up in an ‘appx’ file (essentially the same package used for Windows 8/10 UWP).

So who’s changed?

I noticed that JetBrains went to a non-MSI installer with their ReSharper 9.x release. They were already using NuGet packages for managing extensions. I think they’ve kind of gone the whole way with their installer now.

It also appears that Visual Studio “15” (not to be confused with the current 2015 release which is version 14) is moving to a non-MSI installer as part of reducing the install process.

ASP.NET for a while now has had the ‘msdeploy’ packaging. It’s what is used when you choose ‘Publish’ from the context menu in Visual Studio.

So what now?

MSI still has a role, especially for traditional server deployments, but if you want to support deployments to Nano then you’ll need to look at appx. If you have a desktop app that you’d like to feature in the Windows Store, then appx is also a requirement.

There’s currently a couple of options if you want to move towards appx deployments:

Project Centennial – aka the Desktop Converter for Win32 or .NET 4.6.1 apps. This is currently in preview (and requires that you run on a preview release of Windows 10).

WiX AppX Extension – a commercial product created by some of the main WiX developers that lets you leverage your existing WiX projects to produce an Appx package.

Sunday, 3 July 2016

A tale of two cities

Last month I was delighted to be able to speak at the Sydney .NET User Group on “Enhancing .NET Unit Tests”. Thanks to group leader Adam Cogan for hosting a great meeting. If you’re in Sydney or passing through then I’d definitely recommend dropping in. If you can’t get there in person, they also live-stream the user group meetings as well as publish the recordings to YouTube.

NDC Sydney had around 600 submissions for only 125 sessions, so I didn’t feel so bad when I heard my session proposal had missed out. I do think this is going to be one of the biggest developer conferences Australia has ever seen, so I was still really keen to get there somehow. When I was offered the chance to go as a volunteer crew member, I jumped at the opportunity. I’ll work half the time helping at the conference, and the remaining time I’ll be able to attend sessions.

Here’s the recording from my Sydney .NET talk..

But you may not need to watch if you’re going to DDD Melbourne! It’s on Saturday 13th August (a week after NDC Sydney), and I just heard that my session has been accepted! I’ll be presenting “10 tools and libraries to enhance .NET unit testing” – which is going to be quite similar to the talk above, so come along and see it live Smile Apparently DDD Melbourne is a sell-out again, so it should be a great day.

August is going to be a busy month!

Thursday, 12 May 2016

Analysing .NET code dependencies–Visual Studio Code Maps

This is the second in a series of posts on reviewing tools to help analyse code dependencies in .NET

Code Maps is a feature that was first included in Visual Studio 2012 Ultimate. It remains an Enterprise-only feature in 2015, though Professional and Community editions can view previously created diagrams.

Code Maps operate from the cross-project solution level right down to the method level.

Dependencies

To generate a map of project dependencies, go to the Architecture menu, and choose Generate Code Map for Solution.

A new window opens and gradually items appear on the diagram. Usually this will trigger a build of the solution, and then the analysis process will run, eventually displaying the dependencies between the projects.

Code Maps - Solution

If your solution uses solution folders to group similar projects, then you’ll see that represented in the diagram (the OLW solution doesn’t currently do this).

You can then expand this out by selecting all the nodes (Ctrl-A) and choosing Group, Expand from the context menu.

Code Maps - Solution expanded with externals highlighted

You can see two things – the OpenLiveWriter.PostEditor project seems to be the most significant project, and also there’s an ‘Externals’ block with all external assembly references. To just focus on strictly code from the solution, you can select this group and press Delete. This removes it from the diagram.

Editing a Code Map diagram doesn’t mess with your source code, as the diagrams are a bit like a snapshot of your code at the time they were created. In some ways this is a limitation, but one positive aspect is that you can use Code Map diagrams to model or prototype changes to the class hierarchy and dependencies without having to commit those changes in code.

Let’s focus in on the PostEditor project. If we select that node, we can choose New Graph from the context menu. A separate diagram is now displayed with just the contents of the previously selected node. You can use the Filters tool window to select which elements you want to display. I de-selected Assembly so that I can now focus on the namespaces.

Code Maps - HtmlEditor assembly classes

Let’s keep going further in. Select the OpenLiveWriter.PostEditor namespace, and open this in a new graph again. To drill down to the class level, select all nodes again (Ctrl-A) and choose Group, Expand again.

Code Maps - OpenLiveWriter.HtmlEditor namespace classes

Let’s click on that top node – BlogPostEditingManager. Repeating the same process again, and filtering down to just methods, we get the following:

Code Maps - BlogPostEditingManager Methods

We now have a call graph of the methods inside the class. I also changed the layout for this graph to be ‘left to right’. The two blue nodes represent classes defined inside this class.

Usually, you’d expect to see public methods on the left, and non-public methods going to the right. Unfortunately there’s no way distinguish between them apart from hovering over a node and reading the tooltip that appears, or by selecting a node and reviewing the details in the Properties window.

Debugging

You can also display Code Maps while debugging. If you have stopped at a breakpoint, you can right-click and select Show Call Stack on Code Map.

Code Maps - Call stack

Basically just a different way see the same info that gets displayed in the Call Stack debugging window, and unless I’ve missed something obvious, I think I’ll stick with the latter.

Summary

That’s a quick overview of some of the things that Code Maps can show you. They are entirely visual, so unlike NDepend, there’s no way to do any custom querying out of the box. On the other hand, the fact that the diagrams use DGML (directed graph markup language), it would be possible to write code that queried the file directly.

Friday, 29 April 2016

Analysing .NET code dependencies–NDepend

This is the first in a series of posts on reviewing tools for analysing .NET code dependencies.

I last wrote about NDepend briefly four years ago, and with a bit more detail way back in 2010. Some of the features added since then include:

  • Support for Visual Studio 2013 and 2015
    • Now a proper VSIX extension (v6)
    • NDepend project can be included in VS solution.
  • New Dashboard Panel – state of your code base at a glance
  • Focus on recent rules violations – only show rule violations on added/modified code
  • UI enhancements – improved menus
  • Better path management – UNC paths and support for environment and MSBuild variables.
  • Windows Store and Windows Phone support – honours the TypeForwardedToAttribute
  • Trend monitoring – monitor trend metrics and view via trend charts
  • Share rules between projects
  • Rules
    • Rule descriptions and fix suggestions added
    • Reduction in false positive detection
  • TFS integration
    • 2013 (2015 is coming)
  • SonarQube integration
  • TeamCity integration
  • Report enhancements – report includes trend metric charts
  • More console options – additional parameters to support file and directory variables.
  • Coloured Code Metric view – treemap elements can be coloured to indicate second metric
  • Code coverage shown with red/green colouring
  • Improved handling of compiler-generated code
  • Async support
  • High DPI support
  • Visual Studio theme support

So let’s take NDepend v6 for a spin and see what it can do.

I’m going to use the Open Live Writer code base for these reviews. The writer.sln contains 28 projects and around 3,000 types.

The OLW solution is special in that most projects point to the same single output folder. As a result you might have to tell NDepend to look in this output directory rather than just relying on it to examine the solution’s projects. Once the assemblies are selected, the analysis begins.

Analysis might take a minute or two, but when it finishes you are prompted to view the results. I chose the Dashboard view:

NDepend Dashboard view

To dig into the dependencies, let’s look at some useful diagrams. First up, the Dependency Graph. Go to NDepend, Graph, View Application Assemblies Only.

Assembly dependency graph

By default, the size of each ‘node’ indicates the relative number of IL instructions in that assembly. From the graph above, it’s obvious that OpenLiveWriter.PostEditor is the largest assembly. That sounds reasonable given that OLW is all about editing posts.

Switching to the Matrix, here again is the ‘Application Assemblies Only’ view:

Matrix View of Dependencies

The intersections where there are 0 methods used from the assembly reference bear further investigation. Sometimes there might be a valid reason, but quite often this represents an unnecessary assembly reference that can be removed.

The query language is very powerful. I’d like to find assemblies that are only referenced by one other assembly. Matching assemblies could be candidates for merging with the parent assembly if there’s no good reason for keeping them separate.

I came up with this custom query:


from m in Assemblies.ExceptThirdParty()
where m.AssembliesUsingMe.Count() == 1
select new { Parent = m.AssembliesUsingMe.First() , Child = m}

Which returned the following results:

  • OpenLiveWriter.FileDestinations
  • OpenLiveWriter.HtmlEditor
  • OpenLiveWriter.InternalWriterPlugin

Are all referenced only by OpenLiveWriter.PostEditor. That’s useful to know.

Jumping back to the dashboard, let’s drill in to see some of those “Critical Rules Violated”. Clicking on this heading in the dashboard opens the Queries and Rules Explorer, with the “14 Critical Rules Violated” filter selected.

Selecting the top item in the list opens the Queries and Rules Edit window, with the top half showing the actual query that was used to search for the violations and the bottom half showing a tree of matches for this rule (in this case it’s the offending methods). So that Init() method takes 15 parameters. Maybe that’s ok, maybe not.

NDepend Queries and Rules Edit

I love digging around the results of these kinds of rule queries. Particularly the ones around potential dead code, where you end up identifying and removing code that isn’t being used anymore.

NDepend has really progressed over the years. It’s particularly nice to see the improved integration with Visual Studio. Ideally every developer would have NDepend in their toolbox to use themselves, but a first step is probably including it as part of your build pipeline. That way, at least everyone can view the reports it generates as part of the build results.

Analysing .NET code dependencies–Overview

How can you tell if modules/components in your application are loosely-coupled between each other, and tightly cohesive internally? You could read the code line-by-line, but that becomes difficult once the codebase becomes large.

It can be very valuable to be able to visualise the the dependencies between the various components that make up your application – both at the class and module/assembly level. These tools analyse code, either by parsing the source code, or by analysing the compiled assemblies to produce various summaries and reports about the state of the code.

I’m planning to spend a bit of time in future blog posts reviewing a number of these tools that can help with this analysis, including:

I’m also interested to hear what you use. Let me know in the comments of your experiences with these or other tools I haven’t mentioned.

Monday, 11 April 2016

My new Dell XPS 15 laptop

My birthday has come early this year. I've finally bought a new laptop! It wasn’t the cheapest either, so I think that will cover a couple more birthdays in the future too Smile

I'd been evaluating a number of different manufacturers and models, and eventually went with a Dell XPS 15 (9550). I'd had a pretty good run with my old XPS 1645 and that counted in the XPS 15's favour.

I bought the 1645 in 2010, so I was expecting to buy something that represented 6 years of technology improvements. So far I think the 15 delivers that.

  • 16GB DDR4
  • 512GB SSD (PCIe)
  • 4K Ultra HD (3840 x 2160) touch display

Modifications

Out of the box, the top row of the keyboard defaults to the feature keys. I make use of the Function keys (F1, F2, etc) much more than I'd use the feature keys (Mute, Volume Up/Down, etc) so I went into the UEFI firmware settings and changed that to default to function keys.

Here’s a comparison of the keyboards of the 1645 and 15 (the shiny strip above the main keyboard on the 1645 has the feature keys). Obviously fashions change too – from glossy/shiny to matte.

XPS 1645 KeyboardXPS 15 keyboard

I HATE touchpads that simulate a mouse click with a single tap. Maybe it's my hands but I find I end up 'clicking' a lot more than I intended. So it's another thing I try to disable if possible. On the 1645 this was done through the Synaptics touchpad driver, but that isn't present on the 15. Instead it turns out that's a setting provided by Windows itself.

Windows 10 Touchpad settings

Old and new comparison

XPS 15 and 1645 closedXPS 15 and 1645 open

Here’s the 15 sitting on top of the 1645, to show it’s slightly smaller.

View from above of XPS 15 sitting on top of 1645

Side views show the 15 is a fair bit slimmer. The 1645 comes with VGA, HDMI and DisplayPort ports – the 15 just has a single HDMI, but you can get an external adapter with a second HDMI and VGA (as well as extra USB and Ethernet). No DVD drive in the 15 either!

XPS 15 and 1645 right side comparisonXPS 15 and 1645 - left side comparison

The rubber feet of the 1645 fell off a while ago – both the ones on the base of the laptop and the ones fixed to the battery bar. The 15 has two rubber strips. Time will tell if they last longer.

XPS 1645 underneath - worn feetXPS 15 - underneath showing rubber feet strips

My 1645 weighs 3.065kg. I’m pleased to see the 15 weighs only 2.040kg. (For those days when I need to carry it around, my back is also pleased!)

XPS 1645 Weight - 3.065KGXPS 15 2.040kg

It’s not easy to show the difference in displays, but this gives you a bit of an idea of the 4K display of the 15 next to the standard 1080 of the 1645. It doesn’t show up here, but the 1645 screen also got quite scratched over the years from rubbing against the keyboard. Probably made worse from the extra rubber pads falling off that should have prevented this. I’m looking into getting a protective cloth for the new laptop to try and reduce the chance of that happening again.
Comparing the displays of 15 and 1645

And check out the disk performance – almost 10x faster with the PCIe SSD – nice!

HDTune Benchmark Crucial CT512MX1 SSD - Average 111 MB/secHDTune Benchmark NVMe THNSN5512GPU7_NV - Average 897 MB/sec

Finally, I’d forgotten what it was like to have a battery that holds a decent amount of charge (the 1645 might say it has 1:45 left, but that’s pretty optimistic). I can sit on the sofa with the XPS 15 and it lasts the whole evening. Wow Smile

dell xps 1645 batteryDell XPS 15 Battery

Monday, 28 March 2016

Installing future SQL Server updates with confidence

Great to read that Microsoft are now making the “cumulative update” packages ‘recommended’ installs, and the updates themselves will be easier to obtain - no longer requiring a email address to download directly, and also being listed in Windows Update Catalog (and maybe in the future as an optional update on Microsoft Update).

As a developer, I’ve often installed the latest CU (cumulative update) just because I like to be current on my own PC – but I’ve traditionally been more conservative with production SQL Servers that I’ve had to look after over the years. In the latter case I’ve installed the latest service pack, but only added a CU if it seemed likely to address any issue we might be having at the time.

With this change, now pushing out the latest CU can be done with more confidence and probably should be considered part of maintaining your SQL Server infrastructure. Quoting from the above article:

You should plan to install a CU with the same level of confidence you plan to install SPs (Service Packs) as they are released. This is because CU’s are certified and tested to the level of SP’s.

A few years back I remember thinking that the SQL Server team had really set the standard for releasing regular updates for their products (especially compared to the lack of updates at the time to fix problems with older versions of Visual Studio 2005/2008). Since then the VS team have upped their game, and now they are pushing new major servicing updates out around every quarter. That doesn’t include out-of-band updates to VS extensions that are done more frequently.

So it’s great to see the SQL Server team stepping up the pace another notch.

Tuesday, 15 March 2016

How I first heard about Lean

A quick shout-out to Flinders Medical Centre’s Redesigning Care. They implemented Lean a few years ago to improve how their hospital functioned. After hearing about what Lean was and what they were doing, I then discovered that Lean had been applied to developing software too.

If you’re interested in learning more about Lean in a healthcare setting, contact them via their webpage, or check out their overview video on YouTube