C#: Getting Feedback From Hosted Web PI GUI

The previous post explained how to host the Microsoft Web Platform Installer (WPI) in an own Windows Forms application. It’s nice that we can do that, but it only really makes sense when you need to perform special actions depending on the parameters determined by WPI during installation. Continue reading

C#: Hosting Web PI GUI In Own Application

The Microsoft Web Platform Installer (WPI) is a very cool tool for installing frameworks, programs and web application. It automatically resolves installs dependencies, which makes it my top choice for deploying my own applications.

In some cased, I need to install multiple applications and update their local configuration to contain data of other applications (e.g., the web site URL of one application gets written to the web.config of another application). The installer application internally uses WPI to perform the dependency resolving and the actual installation. The installer application itself performs the cross-application configuration and installs other components not installable via WPI.

This post shows how to integrate WPI’s GUI into a custom application. Continue reading

C#: Test For Elevated Privileges

So you want to know if your current code is has been “run as administrator”? You’ll need to check if the current Windows User has the built-in role “Administrator”. To make things short, here you go:

using System.Security.Principal;

// ...

var windowsIdentity = WindowsIdentity.GetCurrent();
var windowsPrincipal = new WindowsPrincipal(windowsIdentity );
var hasElevatedPrivileges = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

Modify Web Platform Installer Configuration with C#

Suppose you intend to call the Web Platform Installer (WPI) from C# code or from the PowerShell. Suppose you want to provide a custom feed or want to change the address of the remote db server and display WPI to the user to perform an installation. Unfortunately, you cannot supply configuration parameters to the UI version of WPI (WebPlatformInstaller.exe). The command-line version (WebPiCmd.exe) can be supplied with all necessary parameters, but does not display a nice UI to the user so he\she can conveniently configure the installed application.

This post shows how to modify the WPI preferences file using C#. This file contains the configuration of the UI version of Web Platform Installer. Continue reading

TFS: Get And Modify Included And Excluded Pending Changes in Visual Studio

In this post on Stack Overflow, I posted code that allows access to the included/excluded pending changes that the user can modify via the “Pending Changes” tab on the Visual Studio Team Explorer. Here it is again… Continue reading

Reflection Emit and Type Inheritance: Calling Base Type Constructors

Suppose you want to use Reflection.Emit to generate a dynamic type in memory. Suppose this dynamic type should inherit a custom base type, and you want to put the default implementation into this base type. In plain C#, you would write…

class MyDynamic : MyBase
    public MyDynamic()

… but with Reflection.Emit, there’s a gotcha. Continue reading