Friday, 2 June 2017

Writing ProductVersion to a text file during installation

Today I was tasked with creating a text file during the running of an MSI installer, and writing the app's ProductVersion to it, so that our remote admin tools could read at a glance what versions our users were running.

First of all I needed to create an Installer Class in the app, and then override the Install method like so, capturing an input parameter and writing it to a text file:

 public override void Install(IDictionary savedState)
        {
            base.Install(savedState);

            string version = Context.Parameters["Version"];

            string path2 = "C:\\MyFile.txt";

            try
            {
                FileStream fs1 = new FileStream(path2, FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter writer1 = new StreamWriter(fs1);
                writer1.Write("Version:" + "\r\n" +
                             version);
                writer1.Close();
            }
            catch (Exception)
            {
               //do something here if you need to
            }
}

Then, in the Setup project,  I added Custom Action. Right-click on the project, go to View > Custom Actions. Right-click on the install folder, and select Add Custom Action. Browse to the Application folder, select the primary output, and click 'Add Output'. Then, select the thing you've just added, and in the properties window, do the following:


Thursday, 18 May 2017

Visual Studio 2017 freezes / crashes when I open the toolbox

I recently installed VS 2017 on a new Win 10 machine, and I had a problem when trying to open the toolbox window - the whole IDE would just freeze and never recover.

This is a problem with the Xamarin extension that is yet to be fixed, apparently it is trying to warn us something about the Android SDK (that it might not be installed?), but instead it brings the whole thing to a halt. The quick fix is to disable the Xamarin extension - but I guess installing the Android SDK may fix it too.

Friday, 10 March 2017

Visual Studio 2017 install stuck on Applying Microsoft.VisualStudio.Debugger.JustInTime

This happened to me and I tried lots of things to overcome the problem - eventually I found I had to this:


  • Switch off AVG antivirus protection
  • Switch off  'Real-time protection' on your Windows Defender settings
  • Restart
After restart my install started where it left off and didn't get stuck again!

Tuesday, 28 February 2017

Winforms - showing touch keyboard on Win 10

If you're using a textbox in a winforms app on Windows 10 in tablet mode the touch keyboard only seems to show if your textbox is a password box. Weird huh? There's a few proposed solutions for this to do with tabtip.exe or osk.exe but neither of these worked for me. The most effective solution was to:


Insert a reference to UIAutomation.dll
    In the form-load-handler of the application's main window, insert the following code:
      var asForm = System.Windows.Automation.AutomationElement.FromHandle(this.Handle);

      Friday, 13 January 2017

      cIgnore SSL HTTPS errors GetAsync Httplient .Net winforms

      I'm working on a Windows app at the moment and part of the job involves comms with a Rest api over https. During the development phase the SSL certs for the server aren't valid, and this causes GetAsync for the HttpClient to return a Taskstatus.Faulted, and the whole thing breaks. To overcome this you just need this line of code:

      ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;