-
Notifications
You must be signed in to change notification settings - Fork 177
VS2019 – 2022 Templates
Wix# comes with various VS2019/2022 project/item templates. They are all packed into Visual Studio Extension - WixSharp Project Templates, which can be downloaded from the Visual Studio Gallery or directly installed from the VS Extension manager.
The extension includes multiple project templates. The type of the project is reflected in the temple name. I.e. "WixSharp Managed Setup - Custom UI" is a template for the managed project WixSharp that has source code for all UI dialogs included in the Visual Studio project.
WiX Toolset installation
Wix# does require WiX binaries (compilers, linkers etc.). Wix# is capable of automatically finding WiX tools only if WiX Toolset is installed. In all other cases, you need to set the environment variable WIXSHARP_WIXDIR
or WixSharp.Compiler.WixLocation
to the valid path to the WiX binaries.
WiX 3
WiX binaries can be brought to the built environment by either installing WiX Toolset, downloading Wix# suite or by adding WixSharp.wix.bin
NuGet package to your project. For bringing WiX Tools from NuGet use Install-Package WixSharp.wix.bin
command.
WiX 4
The binaries need to be installed as .NET Tool:
dotnet tool install --global wix
It is important to understand what is involved in building the MSI as otherwise it may be quite uneasy to troubleshoot the integration problems associated with the use of NuGet, VS and MSBuild.
Every Wix# VS project is a C# project that defines and builds an exe. This exe is an "MSI builder", which executes WiX compilers to produce the final msi. Thus your program.cs
file with static Main(...)
is a build script that builds msi file. Interestingly enough, in the early releases of WixSharp (e.g. for WiX3) program.cs
file was executed as a script, not as an application executable.
Thus if you just create manually a simple ConsoleApp project with the Wix# code (as below) and compile it it will build an exe but not msi.
class Script
{
static public void Main()
{
var project = new Project("CustomActionTest",
new ManagedAction("MyAction", Return.check,
When.After, Step.InstallInitialize,
Condition.NOT_Installed));
project.BuildMsi();
}
}
public class CustomActions
{
[CustomAction]
public static ActionResult MyAction(Session session)
{
MessageBox.Show("Hello World!");
return ActionResult.Success;
}
}
However, if you run the produced exe (e.g. F5) it in turn will build the desired msi.
Thus building MSI involves these two steps:
- Compiling your build script (console application project) containing the C# code defining your setup (Project or ManagedProject).
- Executing your compiled build script as a VS post-build event. This will produce the msi file.
And the overall building process is below:
Note, instead of running the exe manually every time VS project template automates it by setting the project post-build event scheduled in the project file.
The post-build event contains three important instructions:
- Sets the current directory to the VS project directory. Required for WiX compilers.
- Sets environment variable
ide
. Required for WixSharp. - Executes the compiled build script.
Project file (*.csproj):
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="cd .\
set ide=true
"$(TargetPath)"" />
</Target>
Project properties dialog:
If you need to use MSBuild context in your build script pass it to the build script as a CLI argument:
And then in the build script use the argument as you wish:
static void Main(string[] args)
{
var myArg = args.FirstOrDefault(x=>x.StartsWith("-myArg"))?.Split(':').Last();
If for whatever reason, you want to disable building the msi and focus on troubleshooting/building the build script executable then you can simply temporarily disable the post-build event as you would do it in any VS project.
- Home - Overview
- Architecture
- Documentation
- Samples Library
- Product Roadmap
- Tips'n'Tricks