Addressing PR feedback.

Moved the MSI generation to the Windows pack from the base class.
Renamed the enum to better reflect its purpose.
This commit is contained in:
Kevin Bost
2025-01-30 23:08:15 -08:00
committed by Caelan
parent e9871e1656
commit c8688ebefb
9 changed files with 35 additions and 47 deletions

View File

@@ -20,8 +20,8 @@ namespace Velopack
Portable = 3,
/// <summary> An application installer archive. </summary>
Installer = 4,
/// <summary> A Windows Installer package (.msi) for the application.</summary>
Msi = 5,
/// <summary> A Windows Installer package (.msi) for the deployment tool.</summary>
MsiDeploymentTool = 5
}
/// <summary>

View File

@@ -37,5 +37,4 @@ public class LinuxPackOptions : IPackOptions
public string Categories { get; set; }
public string Compression { get; set; }
public bool BuildMsi => false;
}

View File

@@ -119,7 +119,7 @@ public class OsxPackCommandRunner : PackageBuilder<OsxPackOptions>
return Task.CompletedTask;
}
protected override Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string pkgPath)
protected override Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string pkgPath, Func<string, VelopackAssetType, string> createAsset)
{
// create installer package, sign and notarize
if (!Options.NoInst) {

View File

@@ -35,5 +35,4 @@ public class OsxPackOptions : OsxBundleOptions, IPackOptions
public string Channel { get; set; }
public string Exclude { get; set; }
public bool BuildMsi => false;
}

View File

@@ -183,11 +183,24 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
return String.Join(",", validated);
}
protected override Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string targetSetupExe)
protected override Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string targetSetupExe, Func<string, VelopackAssetType, string> createAsset)
{
void setupExeProgress(int x)
{
if (Options.BuildMsi) {
progress(x / 2);
} else {
progress(x);
}
}
void msiProgress(int value)
{
progress(50 + value / 2);
}
var bundledZip = new ZipPackage(releasePkg);
IoUtil.Retry(() => File.Copy(HelperFile.SetupPath, targetSetupExe, true));
progress(10);
setupExeProgress(10);
var editor = new ResourceEdit(targetSetupExe, Log);
editor.SetVersionInfo(bundledZip);
@@ -197,14 +210,20 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
editor.Commit();
progress(25);
setupExeProgress(25);
Log.Debug($"Creating Setup bundle");
SetupBundle.CreatePackageBundle(targetSetupExe, releasePkg);
progress(50);
setupExeProgress(50);
Log.Debug("Signing Setup bundle");
SignFilesImpl(CoreUtil.CreateProgressDelegate(progress, 50, 100), targetSetupExe);
SignFilesImpl(CoreUtil.CreateProgressDelegate( setupExeProgress, 50, 100), targetSetupExe);
Log.Debug($"Setup bundle created '{Path.GetFileName(targetSetupExe)}'.");
progress(100);
setupExeProgress(100);
if (Options.BuildMsi && VelopackRuntimeInfo.IsWindows) {
var msiName = DefaultName.GetSuggestedMsiName(Options.PackId, Options.Channel, TargetOs);
var msiPath = createAsset(msiName, VelopackAssetType.MsiDeploymentTool);
CompileWixTemplateToMsi(msiProgress, targetSetupExe, msiPath);
}
return Task.CompletedTask;
}
@@ -241,13 +260,6 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
return dict;
}
protected override Task CreateMsiPackage(Action<int> progress, string setupExePath, string msiPath)
{
if (VelopackRuntimeInfo.IsWindows) {
CompileWixTemplateToMsi(progress, setupExePath, msiPath);
}
return Task.CompletedTask;
}
private void CreateExecutableStubForExe(string exeToCopy, string targetStubPath)
{

View File

@@ -9,5 +9,4 @@ public interface IPackOptions : INugetPackCommand, IPlatformOptions
string Exclude { get; set; }
bool NoPortable { get; set; }
bool NoInst { get; set; }
bool BuildMsi { get; }
}

View File

@@ -29,7 +29,7 @@ public abstract class PackageBuilder<T> : ICommand<T>
protected Dictionary<string, string> ExtraNuspecMetadata { get; } = new();
private readonly Regex REGEX_EXCLUDES = new Regex(@".*[\\\/]createdump.*|.*\.vshost\..*|.*\.nupkg$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private readonly Regex REGEX_EXCLUDES = new(@".*[\\\/]createdump.*|.*\.vshost\..*|.*\.nupkg$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public PackageBuilder(RuntimeOs supportedOs, ILogger logger, IFancyConsole console)
{
@@ -148,14 +148,13 @@ public abstract class PackageBuilder<T> : ICommand<T>
});
Task setupTask = null;
string setupExePath = null;
if (!Options.NoInst && TargetOs != RuntimeOs.Linux) {
setupTask = ctx.RunTask(
"Building setup package",
async (progress) => {
var suggestedName = DefaultName.GetSuggestedSetupName(packId, channel, TargetOs);
var path = setupExePath = assetCache.MakeAssetPath(suggestedName, VelopackAssetType.Installer);
await CreateSetupPackage(progress, releasePath, packDirectory, path);
var path = assetCache.MakeAssetPath(suggestedName, VelopackAssetType.Installer);
await CreateSetupPackage(progress, releasePath, packDirectory, path, assetCache.MakeAssetPath);
});
}
@@ -177,16 +176,6 @@ public abstract class PackageBuilder<T> : ICommand<T>
if (TargetOs != RuntimeOs.Linux && portableTask != null) await portableTask;
if (setupTask != null) await setupTask;
if (!Options.NoInst && Options.BuildMsi && TargetOs == RuntimeOs.Windows) {
await ctx.RunTask(
"Building MSI package",
async (progress) => {
var msiName = DefaultName.GetSuggestedMsiName(packId, channel, TargetOs);
var msiPath = assetCache.MakeAssetPath(msiName, VelopackAssetType.Msi);
await CreateMsiPackage(progress, setupExePath, msiPath);
});
}
await ctx.RunTask(
"Post-process steps",
(progress) => {
@@ -282,12 +271,7 @@ public abstract class PackageBuilder<T> : ICommand<T>
return Task.FromResult(dp.PackageFile);
}
protected virtual Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string outputPath)
{
return Task.CompletedTask;
}
protected virtual Task CreateMsiPackage(Action<int> progress, string setupExePath, string msiPath)
protected virtual Task CreateSetupPackage(Action<int> progress, string releasePkg, string packDir, string outputPath, Func<string, VelopackAssetType, string> createAsset)
{
return Task.CompletedTask;
}
@@ -313,10 +297,7 @@ public abstract class PackageBuilder<T> : ICommand<T>
progress(100);
}
protected virtual Dictionary<string, string> GetReleaseMetadataFiles()
{
return new Dictionary<string, string>();
}
protected virtual Dictionary<string, string> GetReleaseMetadataFiles() => [];
protected virtual void CopyFiles(DirectoryInfo source, DirectoryInfo target, Action<int> progress, bool excludeAnnoyances = false)
{
@@ -364,7 +345,7 @@ public abstract class PackageBuilder<T> : ICommand<T>
// copy the contents of the folder, not the folder itself.
var src = source.FullName.TrimEnd('/') + "/.";
var dest = target.FullName.TrimEnd('/') + "/";
Log.Debug(Exe.InvokeAndThrowIfNonZero("cp", new[] { "-a", src, dest }, null));
Log.Debug(Exe.InvokeAndThrowIfNonZero("cp", ["-a", src, dest], null));
if (excludeAnnoyances) {
foreach (var f in target.EnumerateFiles("*", SearchOption.AllDirectories)) {

View File

@@ -76,8 +76,7 @@ public class WindowsPackCommand : PackCommand
AddOption<bool>((v) => BuildMsi = v, "--msi")
.SetDescription("Compile a .msi machine-wide deployment tool.")
.SetHidden()
.SetArgumentHelpName("BITNESS");
.SetHidden();
AddOption<string>((v) => MsiVersionOverride = v, "--msiVersion")
.SetDescription("Override the product version for the generated msi.")

View File

@@ -13,7 +13,6 @@ using Velopack.Util;
using Velopack.Vpk;
using Velopack.Vpk.Logging;
using Velopack.Windows;
using static Azure.Core.HttpHeader;
namespace Velopack.Packaging.Tests;