Skip to content

Commit

Permalink
wix4: #1708: Support for MSIX Installer in Wix#
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Jan 17, 2025
1 parent 57f826a commit b351572
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
</ExclusionItems>
</Settings>
<PrepareComputer DisableWindowsSearchService="false" />
<SaveLocation PackagePath=".\MyProduct.msix" TemplatePath=".\MyProduct.msix.g.xml" />
<Installer Path=".\MyProduct.msi" InstallLocation="C:\Program Files (x86)\My Company" />
<PackageInformation PackageName="MyProduct" PackageDisplayName="MyProduct" PublisherName="CN=MyApp" PublisherDisplayName="oleg" Version="1.0.0.0" p4:PackageDescription="MyProduct" xmlns:p4="http://schemas.microsoft.com/msix/msixpackagingtool/template/1910" />
<SaveLocation PackagePath="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Build-MSIX\MyProduct.msix" TemplatePath=".\MyProduct.msix.g.xml" />
<Installer Path="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Build-MSIX\MyProduct.msi" InstallLocation="C:\Program Files (x86)\My Company" />
<PackageInformation PackageName="MyProduct" PackageDisplayName="MyProduct" PublisherName="CN=oleg" PublisherDisplayName="oleg" Version="1.0.0.0" p4:PackageDescription="MyProduct" xmlns:p4="http://schemas.microsoft.com/msix/msixpackagingtool/template/1910" />
</MsixPackagingToolTemplate>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="MSIX\**" />
<EmbeddedResource Remove="MSIX\**" />
<None Remove="*.cmd" />
<None Remove="MSIX\**" />
<None Remove="CustomAction.config" />
<None Remove="*.exe" />
<None Remove="*.pdb" />
Expand Down
41 changes: 30 additions & 11 deletions Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ static class Script
{
static public void Main()
{
// "msiexec".Run("/uninstall MyProduct.msi -");
// return;
var project =
new ManagedProject("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
Expand All @@ -29,15 +27,12 @@ static public void Main()
TargetFileName = "app.exe"
}));

project.ManagedUI = ManagedUI.DefaultWpf; // all stock UI dialogs
project.ManagedUI = ManagedUI.DefaultWpf;
project.GUID = new Guid("6fe30b47-2577-43ad-9a95-1861ba25889b");

var msi = @".\MyProduct.msi";
project.UpdateTemplate(msi, @"D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Build-MSIX\MyProduct.msix.xml");
return;
// var msi = project.BuildMsi();
var msi = project.BuildMsi();

// var msi = @".\MyProduct.msi";
project.UpdateTemplate(@".\MyProduct.msix.xml", msi);

if (WindowsIdentity.GetCurrent().IsAdmin())
{
Expand All @@ -52,9 +47,29 @@ static public void Main()

static class Msix
{
public static void UpdateTemplate(this Project project, string msi, string msixTemplate)
public static void UpdateTemplate(this Project project, string msixTemplate, string msi)
{
XNamespace ns = "http://schemas.microsoft.com/msix/msixpackagingtool/template/1910";

var doc = XDocument.Load(msixTemplate);

doc.Root.FindFirst("SaveLocation")
.SetAttribute("PackagePath", msi.PathChangeExtension(".msix"))
.SetAttribute("TemplatePath", msixTemplate.PathChangeExtension(".g.xml"));

doc.Root.FindFirst("Installer")
.SetAttribute("Path", msi)
// the dir where msi will be installed so MsixPackagingTool can monitor it
.SetAttribute("InstallLocation", @"C:\Program Files (x86)\My Company");

doc.Root.FindFirst("PackageInformation")
.SetAttribute("PackageName", project.Name)
.SetAttribute("PackageDisplayName", project.Name)
.SetAttribute(ns + "PackageDescription", project.Name)
.SetAttribute("PublisherName", $"CN={project.ControlPanelInfo.Manufacturer}")
.SetAttribute("PublisherDisplayName", project.ControlPanelInfo.Manufacturer)
.SetAttribute("Version", project.Version);

doc.Save(msixTemplate);
}

Expand All @@ -65,6 +80,10 @@ public static void ConvertToMsix(this Project project, string msi, string msixTe

public static void ConvertToMsix(this string msi, string msixTemplate)
{
// Note MsixPackagingTool builds msix by installing msi and analyzing system changes and then embedding detected
// changes (e.g. files) in the produced msix.
// Thus it is important to clean up the system after the msi installation.

using (var msiInfo = new MsiParser(msi))
{
var productCode = msiInfo.GetProductCode();
Expand All @@ -75,7 +94,7 @@ public static void ConvertToMsix(this string msi, string msixTemplate)
var startInfo = new ProcessStartInfo
{
FileName = "MsixPackagingTool.exe",
Arguments = $@"create-package --template {msixTemplate} -v",
Arguments = $@"create-package --template {msixTemplate}", // use "-v" for more detailed build output
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Expand All @@ -98,7 +117,7 @@ public static void ConvertToMsix(this string msi, string msixTemplate)
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.WriteLine($"Error: {ex.Message}. Ensure you have installed MsixPackagingTool and MSIX driver.");
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
</ExclusionItems>
</Settings>
<PrepareComputer DisableWindowsSearchService="false" />
<SaveLocation PackagePath="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files\MyProduct_1.0.0.0_x64__yw5rxyn2chjm8.msix" TemplatePath="C:\Users\olegs\OneDrive\Desktop\MyProduct_1.0.0.0_x64__yw5rxyn2chjm8_template.xml" />
<Installer Path="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files\MyProduct.msi" InstallLocation="C:\Program Files (x86)" />
<SaveLocation PackagePath="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files\MyProduct.msix" TemplatePath="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files\MyProduct.msix.xml" />
<Installer Path="D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files\MyProduct.msi" InstallLocation="C:\Program Files (x86)\My Company" />
<PackageInformation PackageName="MyProduct" PackageDisplayName="MyProduct" PublisherName="CN=MyApp" PublisherDisplayName="oleg" Version="1.0.0.0" p4:PackageDescription="MyProduct" xmlns:p4="http://schemas.microsoft.com/msix/msixpackagingtool/template/1910" />
</MsixPackagingToolTemplate>

0 comments on commit b351572

Please sign in to comment.