Dutton's blog

"Cannot set build environment" installing PRISM 4.1 under VS 2012

I can't believe it's been over a year since I last posted, I guess that's F1 for you =)

Anyway, I've had some time this morning to work on personal projects at home and came across a problem trying to install PRISM 4.1 on Visual Studio 2012.

When I try to register the PRISM binaries on my system (RegisterPrismBinaries.bat), I get the following error

PRISM 'VS100COMNTOOLS' not set. Cannot set the build environment

Visual Studio 2012 doesn't register this path.

To fix this, add the following to the start of RegisterPrismBinaries.bat:

SET VS100COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 11.0Common7Tools

Or wherever your vsvars32.bat from Visual Studio 2012 lives.

Rolling back to previous ClickOnce versions

I've been deploying software using Microsoft's ClickOnce mechanism a lot lately and despite enjoying  its simplicity, especially in comparison to some of the more complicated MSI Setup Projects I've inherited, I've found myself slightly nervous about its abililty to turn a simple software code update into a potentially massively distributed network of fail with its Auto Updating feature.

Because of this, you occasionally have a rather urgent need to roll back everyone to the last working version, and this turns out to be rather easy.

In the publish's output folder you will see a file called "<application name>.application". This is the ClickOnce Application Deployment Manifest and contains a load of details about the application and in particular the version to install and where to find it.

You will also see an "Application Files" folder which will contain a folder for each version of your application deployed so far. To revert all of your users to a previous version, simply copy the "<application name>.application" file from the relevant version subdirectory over the one in the root, then either point your users at your ClickOnce location or if you had the application set to check for and apply updates automatically just tell them to restart. The application will detect that there is a "newer" version (even if that version is in fact older) and allow the user to install it.

RichTextBox ScrollToCaret() bug

I recently needed to add selective colour to text in a Windows Forms TextBox. TextBox doesn't support this, but its close sibling RichTextBox does and as they both derive from TextBoxBase, the conversion in code was painless.

The original TextBox control would automatically set the caret (cursor) position to the end of the text and use ScrollToCaret() to ensure the last line was always visible after dynamically adding content. This doesn't quite work the same when called on a RichTextBox as it appears to scroll until just the very top of the caret is visible, resulting in at best a few pixels of the last line's text visible.

Quite a bit of googling of the problem reveals lots of discussion but not much in the way of a suggested solution.

Fortunately, user32.dll provides calls we can use to set the scroll position and we can access these unmanaged functions through P/Invoke as follows:

[StructLayout(LayoutKind.Sequential)]
public class POINT
{
    public int x;
    public int y;


      
Microsoft 70-511 Exam Passed

Last week I passed the Microsoft 70-511: Windows Application Development with Microsoft .NET Framework 4 exam, making me a Microsoft Certified Technology Specialist!

This is the first of four exams I'm aiming to complete in order to become a Microsoft Certified Professional Developer.

How to handle Command Line Arguments in WPF Applications

I've not considered it before as up to now I haven't required it, but obviously in a WPF Application you don't have a nice

static void Main(string[] args)
{
...
}

with a useful string array of arguments like you do in a regular C# console app, so how do you access them?

In a default WPF application, the entry point to the program is the Application object. This object has an event Startup which is fired, unsurprisingly on startup of your app and contains StartupEventArgs. You can query this object to get to your arguments as follows:

public partial class App : Application
 {
   /// 
   /// A static string array containing our start-up command line arguments
   /// 
   public static string[] Args;