Creating a MSI Installer with IronBarCode
An MSI (Microsoft Installer) is a Windows installation package that facilitates the management of software installation, updates, and removal. Using an MSI provides a standardized method for installing applications, which is especially beneficial for enterprise-level deployments.
IronBarCode offers tools to seamlessly integrate with your existing application and convert it into an MSI for easy distribution. It ensures reliable installation across various environments and allows developers to select which components to include or exclude.
This tutorial will briefly demonstrate how to create an MSI file from an example barcode application.
How to Package an Application as an MSI Installer
Start using IronBarcode in your project today with a free trial.
Prerequsites
Before we start on the project, please download the Microsoft Visual Studio Installer Projects extension for the MSI build to work.
Create a MSI Installer
We'll use a Windows Forms App (.NET Framework) project to demonstrate its functionality for this example.
Add a Button
- Navigate to the ToolBox
- Search for Button
- Add the button by drag and down onto the windows form.
Edit the Button Code
Double click on the button component to access the C# code of the form. Below is the logic for the form component, it takes in a barcode and attempts to scan it. This code only scan image and does not work for PDF. Use the ReadPdf method for PDF document.
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MsiInstallerSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All;
IronSoftware.Logger.LogFilePath = "Default.log";
IronBarCode.License.LicenseKey = "IRONBARCODE-MYLICENSE-KEY-1EF01";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Image files (All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
// Load the selected image
using (Bitmap bmp = new Bitmap(openFileDialog.FileName))
{
// Process the image
AnyBitmap anyBitmap = AnyBitmap.FromBitmap(bmp);
// Configure barcode reader options (customize as needed)
var option = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Detailed,
ExpectMultipleBarcodes = true,
ScanMode = BarcodeScanMode.Auto,
};
BarcodeResults result = IronBarCode.BarcodeReader.Read(anyBitmap, option);
if (result.Count > 0)
{
string output = string.Empty;
foreach(var barcode in result)
{
Console.WriteLine($"Barcode Found: {barcode.Text}");
output += barcode.Text + "\n";
}
MessageBox.Show($"Detected Barcodes: \n{output}");
}
else
{
MessageBox.Show("No Barcode found.");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}");
}
}
}
}
}
}
using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MsiInstallerSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All;
IronSoftware.Logger.LogFilePath = "Default.log";
IronBarCode.License.LicenseKey = "IRONBARCODE-MYLICENSE-KEY-1EF01";
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Image files (All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
// Load the selected image
using (Bitmap bmp = new Bitmap(openFileDialog.FileName))
{
// Process the image
AnyBitmap anyBitmap = AnyBitmap.FromBitmap(bmp);
// Configure barcode reader options (customize as needed)
var option = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Detailed,
ExpectMultipleBarcodes = true,
ScanMode = BarcodeScanMode.Auto,
};
BarcodeResults result = IronBarCode.BarcodeReader.Read(anyBitmap, option);
if (result.Count > 0)
{
string output = string.Empty;
foreach(var barcode in result)
{
Console.WriteLine($"Barcode Found: {barcode.Text}");
output += barcode.Text + "\n";
}
MessageBox.Show($"Detected Barcodes: \n{output}");
}
else
{
MessageBox.Show("No Barcode found.");
}
}
}
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}");
}
}
}
}
}
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
Adding a Setup Project
After setting up the form and its controller logic, we need to add a Setup Project to the existing solution to create an MSI installer. The Setup Project allows us to build an installer for the application we just created.
Right-click on the solution, then go to Add > New Project...
For the MSI installer, build the MsiInstallerSample project again in Release mode. Right-click on the Setup Project, then go to Add > Project Output...
To ensure the MSI installer runs smoothly, you must include the following three files in your setup project: onnxruntime.dll
, IronBarcodeInterop.dll
, and ReaderInterop.dll
. These files are generated when you build the project in Release mode:
onnxruntime.dll
: Located at MsiInstallerSample\MsiInstallerSample\bin\ReleaseIronBarcodeInterop.dll
: Located at MsiInstallerSample\MsiInstallerSample\bin\Release\runtimes\win-x86\nativeReaderInterop.dll
: Located at MsiInstallerSample\MsiInstallerSample\bin\Release\runtimes\win-x86\native
If any of these files is missing, you may encounter the following exception message, as noted in this troubleshooting article: Missing DLLs in Creating MSI Installer
Finally, build the Setup Project. The installer will be located at: MsiInstallerSample\SetupProject\Release
Run & Test the Installer
We install the application with the MSI file to ensure everything is running smoothly.
Download MSI Installer Sample Project
You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as a WinFormApp project.