Skip to content

Instantly share code, notes, and snippets.

@fredemmott
Created December 13, 2024 14:45
Show Gist options
  • Select an option

  • Save fredemmott/1047871f102b411c9acf566499c48f84 to your computer and use it in GitHub Desktop.

Select an option

Save fredemmott/1047871f102b411c9acf566499c48f84 to your computer and use it in GitHub Desktop.
wixsharp-as-script
  1. Use the '.Net core' template
  2. Comment out or delete the PostBuild target in the generated csproj; unlike the previous templates, this is in the csproj rather than in the nuget package, so you can easily disable the 'run-with-no-args-after-build' behavior
  3. dotnet build
  4. dotnet run YOUR_ARGS_HERE < don't include Program.cs

Example output

> dotnet run
Required argument missing for command: 'XRFrameTools-Installer'.

Description:
  Build the MSI

Usage:
  XRFrameTools-Installer <SOURCE> [options]

Arguments:
  <SOURCE>  Location of files to include in the installer

Options:
  --version       Show version information
  -?, -h, --help  Show help and usage information



> dotnet run ..\cmake-build-debug-clang\out\Debug

----------------------------------------------------------

Wix project file has been built: C:\Users\fred\code\XRFrameTools\XRFrameTools-Installer\My Product.wxs

Compiling My Product.wxs
Source base directory: C:\Users\fred\code\XRFrameTools\cmake-build-debug-clang\out\Debug

----------------------------------------------------------

MSI file has been built: C:\Users\fred\code\XRFrameTools\XRFrameTools-Installer\My Product.msi

 ProductName: My Product
 Version    : 1.0.0.0
 ProductId  : {e3334ff2-9b8f-4f3c-ba25-5f966f3b7dca}
 UpgradeCode: {e3334ff2-9b8f-4f3c-ba25-5f965f3b7dc9}

 Auto-generated InstallDir ID:
   INSTALLDIR=%ProgramFiles%\My Company\My Product
using System.CommandLine;
using System.Runtime.CompilerServices;
using WixSharp;
using WixToolset.Dtf.WindowsInstaller;
using File = WixSharp.File;
[assembly: InternalsVisibleTo(assemblyName: "XRFrameTools_Installer.aot")] // assembly name + '.aot suffix
void CreateMSI(DirectoryInfo sourceRoot)
{
var project =
new ManagedProject("My Product",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File("bin/XRFrameTools.exe")),
new Property("PropName", "<your value>"));
project.GUID = Guid.Parse("e3334ff2-9b8f-4f3c-ba25-5f965f3b7dc9");
project.SourceBaseDir = sourceRoot.FullName;
project.BuildMsi();
}
var sourceArg = new Argument<DirectoryInfo>(
name: "SOURCE",
description: "Location of files to include in the installer");
var command = new RootCommand("Build the MSI");
command.Add(sourceArg);
command.SetHandler(
CreateMSI, sourceArg);
return await command.InvokeAsync(args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment