Wrap C# Application in .Msi Installer

Wrap C# application in .msi installer

or very expensive (e.g. Advanced Installer).

There is a also a free edition which includes a Visual Studio extension for Advanced Installer, which you can use to build MSI packages.

The following tutorial shows how you can use the features from the free edition ("Simple" project type):

  • https://www.advancedinstaller.com/user-guide/tutorial-ai-ext-vs.html
  • https://www.advancedinstaller.com/user-guide/tutorial-simple.html

P.S. I work on the team building Advanced Installer.

Install Msi file using c#

You can use msiexec.exe to run installer. Here is sample code.

        Process installerProcess = new Process();
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Arguments = @"/i D:\ActivexPractice\test\test\NewFolder1\setup.msi /q";
processInfo.FileName = "msiexec";
installerProcess.StartInfo = processInfo;
installerProcess.Start();
installerProcess.WaitForExit();

How to Download MSI installer with argument for user-id

Login from the program

The best way is to let the user sign-in with the same credentials in your program. This way, your program can use secure OAuth2 authentication to communicate with your back-end API. This also makes it transparent to the user that the program is communicating with the internet.

Include user-id in filename

An other way is to add the user-id to the filename of the installer during download and extract it when the installer runs. You will have to check if your installer tool allows this. Also, only do this if you user-id's are UUID's or something similar as you don't want the user to guess other id's.

App.config

A third option is to add the user-id to the App.config file. There are two ways to do this:

  1. Create your .msi with App.config uncompressed, add a user-id setting with fixed UUID. Your PHP script can lookup the UUID and replace it in the .msi binary before sending it to the user. See code snippet under MST transform
  2. Build the .msi on demand with the custom App.config. This will only work if your webserver is running on Windows or you have a remote Windows build server that can do this job.

MST transform

You could also use an MST transform and use the same binary replace trick as I've explained for point 1 under App.config.

For both options, you could use a PHP script that uses binary-safe functions to replace the values in the installer and sends the file to the user as a download:

<?php
$userId = // TODO get userId from the session or database
$data = file_get_contents("./my-installer.msi");
// I would use UUID's for template and userId, this way the size of the installer remains the same after replace
$data = str_replace("{fe06bd4e-4bed-4954-be14-42fb79a79817}", $userId, $data);
// Return the file as download
header("Cache-Control: public"); // needed for i.e.
header('Content-Disposition: attachment; filename=my-installer.msi');
header('Content-Type: application/x-msi');
header("Content-Transfer-Encoding: Binary");
echo $data;
?>

Serial number

Last method I can think of is to let the program ask for a serial number on first startup and let your website generate a unique serial number for each user.

Visual Studio 10 Application .exe and .msi in a single file

The most simple solution would be using a selfextracting .exe tool. IEXPRESS.exe is already included in Windows. There are of course some with more features.

MVC core MSI builder, how to create installer?

I'm still adjusting to this "modern" world and part of me wonders why you'd want to package a .NET core app as an MSI. I'd think you'd be running it in a docker container or windows server app (appx) in the "cloud" or on nano server which doesn't even support MSI. For actual windows servers I'd assume regular old .NET. (Which I still fondly love.)

That said, I have an open source program called IsWiX (CodePlex) and have a very simple pattern for creating ASP.NET website installers (see video at: https://www.youtube.com/watch?v=pgDf1kv8a-4) and I'd be willing to work with you to come up with a similiar story for asp.net-core mvc apps.

From what I read, .net core apps also have msbuild publish profile support. That is what I use to create the model from which I author my installers. From there I just drag drop my files into IsWiX and let it author all the XML for me.

FWIW website installers have always had a lot of files. Even before nuget and npm a website developer might add a few thousand files to their project just by adding say Infragistics. I once worked on an installer with over 300,000 files. Yikes! I always wished we had a way of just creating an uncompresssed archive of this stuff and IIS could see if as a directory but to my knowledge that never happened.

The MSI world is a declarative world where we need to explicitly list each of those files. Web developers live in a world where they just say "publish" and don't care about those details. That is the gap that I try to bridge with IsWiX.

C# - Executing a exe file which further invokes a msi file

I got this resolved after i added Thread.Sleep(). before "process.WaitForExit()"

Windows installer and setup application into one file?

If you're using Visual Studio's built-in setup project template to generate your installer, then you don't need the setup.exe file at all.

The only thing you need to distribute is the .msi file. That contains everything that a user would need to install your application. The setup.exe file is simply a stub that launches the setup routines from information in the .msi file, which is a database that the Windows Installer uses to install your application. And since these files can be launched by double-clicking on them if the Windows Installer service is installed, you really don't need to distribute the setup.exe bootstrapper if you don't want to.

Some special reasons that you might want to distribute a setup.exe file are:

  • You expect for some reason that your users might not have the required version of the Windows Installer installed on their computer. This is getting to be pretty rare nowadays, especially considering how widespread broadband Internet connections are and how pushy OS vendors are getting with pushing automatic updates. But if your users are "disconnected" (in many senses of the word), you might want to use a setup executable to verify the presence of the necessary version of the Windows Installer, install it if it isn't there, and then launch your .msi file to perform the install. (You cannot run a .msi file if you do not have Windows Installer installed.)

  • You need to support multiple languages. In this case, the setup.exe file can perform a language transformation on the .msi file before launching the installer.

  • You want to manage the installation of several .msi files in sequence. The way that Windows Installer is designed, it's difficult to chain installations of .msi files, which makes it difficult to install dependencies before or after you install your own application's files. A setup.exe file is not subject to the limitations of the Windows Installer, so it can be used to chain these and precisely manage the order of installation.

  • In general, creating your own setup.exe file (or using one of the many third-party installer software packages to create it for you) gives you significantly greater flexibility. You essentially have complete control over the installation process, rather than having to follow the rules of Windows Installer.

But 83.44% of the time, this isn't necessary and you should follow the much simpler route of using an .msi file. This also allows system administrators to automate installs across machines that they manage (for example, throughout a corporate network), something that is not supported for raw executable files.



Related Topics



Leave a reply



Submit