Working on bundling Velopack.Build

This commit is contained in:
Caelan Sayler
2024-03-10 20:50:18 +00:00
parent 612e54736f
commit 6873fbce41
7 changed files with 192 additions and 64 deletions

View File

@@ -70,12 +70,14 @@ public class MSBuildLogger(TaskLoggingHelper loggingHelper) : ILogger, IFancyCon
public void WriteTable(string tableName, IEnumerable<IEnumerable<string>> rows, bool hasHeaderRow = true)
{
//Do we need this output for MSBuild?
LoggingHelper.LogMessage(tableName);
foreach (var row in rows) {
LoggingHelper.LogMessage(" " + String.Join(" ", row));
}
}
public System.Threading.Tasks.Task<bool> PromptYesNo(string prompt, bool? defaultValue = null, TimeSpan? timeout = null)
{
//TODO: This API is problematic as it assumes interactive.
return Task.FromResult(true);
}

View File

@@ -4,6 +4,7 @@ using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Velopack.Packaging;
using Velopack.Packaging.Unix.Commands;
using Velopack.Packaging.Windows.Commands;
namespace Velopack.Build;
@@ -25,44 +26,84 @@ public class PackTask : MSBuildAsyncTask
public string PackDirectory { get; set; } = null!;
[Required]
public string ReleaseDirectory { get; set; } = null!;
public string ReleaseDir { get; set; } = null!;
public string? PackAuthors { get; set; }
public string? PackTitle { get; set; }
public string? EntryExecutableName { get; set; }
public string? Icon { get; set; }
public string? ReleaseNotes { get; set; }
public DeltaMode DeltaMode { get; set; } = DeltaMode.BestSpeed;
public string? Channel { get; set; }
public bool PackIsAppDir { get; set; }
public bool IncludePdb { get; set; }
public bool NoPackage { get; set; }
public string? PackageWelcome { get; set; }
public string? PackageReadme { get; set; }
public string? PackageLicense { get; set; }
public string? PackageConclusion { get; set; }
public string? SigningAppIdentity { get; set; }
public string? SigningInstallIdentity { get; set; }
public string? SigningEntitlements { get; set; }
public string? NotaryProfile { get; set; }
public string? BundleId { get; set; }
public string? InfoPlistPath { get; set; }
public string? SplashImage { get; set; }
public bool SkipVelopackAppCheck { get; set; }
public string? SignParameters { get; set; }
public bool SignSkipDll { get; set; }
public int SignParallel { get; set; } = 10;
public string? SignTemplate { get; set; }
protected override async Task<bool> ExecuteAsync()
{
//System.Diagnostics.Debugger.Launch();
HelperFile.AddSearchPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
HelperFile.ClearSearchPaths();
HelperFile.AddSearchPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "..", "vendor");
if (VelopackRuntimeInfo.IsWindows) {
var targetRuntime = RID.Parse(TargetRuntime ?? VelopackRuntimeInfo.SystemOs.GetOsShortName());
if (targetRuntime.BaseRID == RuntimeOs.Unknown) {
//TODO: handle this error case
}
DirectoryInfo releaseDir = new(ReleaseDirectory);
releaseDir.Create();
var options = this.ToWinPackOptions();
var runner = new WindowsPackCommandRunner(Logger, Logger);
await runner.Run(new WindowsPackOptions() {
PackId = PackId,
ReleaseDir = releaseDir,
PackDirectory = PackDirectory,
Runtimes = Runtimes,
TargetRuntime = targetRuntime,
PackVersion = PackVersion,
}).ConfigureAwait(false);
Log.LogMessage(MessageImportance.High, $"{PackId} ({PackVersion}) created in {ReleaseDirectory}");
await runner.Run(options).ConfigureAwait(false);
} else if (VelopackRuntimeInfo.IsOSX) {
//TODO: Implement
var options = this.ToOSXPackOptions();
var runner = new OsxPackCommandRunner(Logger, Logger);
await runner.Run(options).ConfigureAwait(false);
} else if (VelopackRuntimeInfo.IsLinux) {
//TODO: Implement
var options = this.ToLinuxPackOptions();
var runner = new LinuxPackCommandRunner(Logger, Logger);
await runner.Run(options).ConfigureAwait(false);
} else {
//TODO: Do we really want to fail to pack (effectively failing the user's publish, or should we just warn?
throw new NotSupportedException("Unsupported OS platform: " + VelopackRuntimeInfo.SystemOs.GetOsLongName());
}
Log.LogMessage(MessageImportance.High, $"{PackId} ({PackVersion}) created in {Path.GetFullPath(ReleaseDir)}");
return true;
}
}

View File

@@ -0,0 +1,25 @@
using System.IO;
using Riok.Mapperly.Abstractions;
using Velopack.Packaging.Unix.Commands;
using Velopack.Packaging.Windows.Commands;
namespace Velopack.Build;
[Mapper(
RequiredMappingStrategy = RequiredMappingStrategy.Target,
EnabledConversions = MappingConversionType.None)]
public static partial class TaskOptionsMapper
{
public static partial WindowsPackOptions ToWinPackOptions(this PackTask cmd);
public static partial LinuxPackOptions ToLinuxPackOptions(this PackTask cmd);
public static partial OsxPackOptions ToOSXPackOptions(this PackTask cmd);
private static DirectoryInfo StringToDirectoryInfo(string t)
{
var di = new DirectoryInfo(t);
if (!di.Exists) di.Create();
return di;
}
private static RID StringToRID(string t) => RID.Parse(t);
}

View File

@@ -4,19 +4,64 @@
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
<SignAssembly>false</SignAssembly>
<!--
https://learn.microsoft.com/dotnet/core/project-sdk/msbuild-props?WT.mc_id=DT-MVP-5003472#copylocallockfileassemblies
-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<PropertyGroup>
<Title>Velopack.Build</Title>
<Description>Velopack.Build</Description>
<PackageId>Velopack.Build</PackageId>
<PackageIcon>Velopack_200.png</PackageIcon>
<PackageReadmeFile>README_NUGET.md</PackageReadmeFile>
<Description>Quick and easy installer and automatic updates for cross-platform desktop applications</Description>
<DevelopmentDependency>true</DevelopmentDependency>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/velopack/velopack</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Velopack.Packaging.Unix\Velopack.Packaging.Unix.csproj" />
<ProjectReference Include="..\Velopack.Packaging.Windows\Velopack.Packaging.Windows.csproj" />
<ProjectReference Include="..\Velopack\Velopack.csproj" />
</ItemGroup>
<PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
<PackageReference Include="Riok.Mapperly" Version="3.3.0" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\artwork\Velopack_200.png" Pack="true" PackagePath="\" />
<None Include="..\..\README_NUGET.md" Pack="true" PackagePath="\" />
<None Include="Velopack.Build.targets" Pack="true" PackagePath="build\Velopack.Build.targets" />
</ItemGroup>
<ItemGroup Condition=" $([System.OperatingSystem]::IsWindows()) or '$(PackRustAssets)' == 'true' ">
<None Include="..\Rust\target\release\update.exe" Pack="true" PackagePath="vendor" />
<None Include="..\Rust\target\release\setup.exe" Pack="true" PackagePath="vendor" />
<None Include="..\Rust\target\release\stub.exe" Pack="true" PackagePath="vendor" />
<None Include="..\..\vendor\rcedit.exe" Pack="true" PackagePath="vendor" />
<None Include="..\..\vendor\zstd.exe" Pack="true" PackagePath="vendor" />
<None Include="..\..\vendor\signtool.exe" Pack="true" PackagePath="vendor" />
</ItemGroup>
<ItemGroup Condition=" $([System.OperatingSystem]::IsMacOS()) or '$(PackRustAssets)' == 'true' ">
<None Include="..\Rust\target\release\UpdateMac" Pack="true" PackagePath="vendor" />
<None Include="..\..\Velopack.entitlements" Pack="true" PackagePath="vendor" />
<None Include="..\..\artwork\DefaultApp.icns" Pack="true" PackagePath="vendor" />
</ItemGroup>
<ItemGroup Condition=" $([System.OperatingSystem]::IsLinux()) or '$(PackRustAssets)' == 'true' ">
<None Include="..\Rust\target\release\UpdateNix" Pack="true" PackagePath="vendor" />
<None Include="..\..\vendor\appimagetool-x86_64.AppImage" Pack="true" PackagePath="vendor" />
<None Include="..\..\artwork\DefaultApp_64.png" Pack="true" PackagePath="vendor" />
</ItemGroup>
<!--<PropertyGroup>
</PropertyGroup>
<PropertyGroup Label="MacOS" Condition="$([System.OperatingSystem]::IsMacOS())">
@@ -65,13 +110,7 @@
<None Include="..\..\vendor\zstd.exe" Link="zstd.exe" Visible="false" Condition="$([System.OperatingSystem]::IsWindows())">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup Label="NuGet">
<None Include="Velopack.Build.targets" Pack="true" PackagePath="build\Velopack.Build.targets" />
</ItemGroup>
</ItemGroup>-->
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
</ItemGroup>
</Project>

View File

@@ -1,14 +1,7 @@
<Project>
<PropertyGroup>
<!--
TODO: Should we default this to false?
Is the action of adding the NuGet package sufficient to assume the user wants this to always
create a release on publish?
-->
<VelopackPackOnPublish Condition="$(VelopackPackOnPublish) == ''">true</VelopackPackOnPublish>
<!-- By default we will push if packing is enabled -->
<VelopackPushOnPublish Condition="$(VelopackPushOnPublish) == ''">$(VelopackPackOnPublish)</VelopackPushOnPublish>
<VelopackPushOnPublish Condition="$(VelopackPushOnPublish) == ''">false</VelopackPushOnPublish>
<!--
https://learn.microsoft.com/visualstudio/msbuild/tutorial-custom-task-code-generation?view=vs-2022&WT.mc_id=DT-MVP-5003472#changes-required-to-multitarget
@@ -17,23 +10,25 @@
<VelopackStronglyTyped_TFM Condition=" '$(MSBuildRuntimeType)' == 'Core' ">net6.0</VelopackStronglyTyped_TFM>
</PropertyGroup>
<UsingTask TaskName="Velopack.Build.PackTask"
AssemblyFile="..\..\build\$(Configuration)\$(VelopackStronglyTyped_TFM)\Velopack.Build.dll"/>
<UsingTask TaskName="Velopack.Build.PublishTask"
AssemblyFile="..\..\build\$(Configuration)\$(VelopackStronglyTyped_TFM)\Velopack.Build.dll"/>
<UsingTask TaskName="Velopack.Build.PackTask" AssemblyFile="..\..\build\$(Configuration)\$(VelopackStronglyTyped_TFM)\Velopack.Build.dll"/>
<UsingTask TaskName="Velopack.Build.PublishTask" AssemblyFile="..\..\build\$(Configuration)\$(VelopackStronglyTyped_TFM)\Velopack.Build.dll"/>
<Target Name="_VelopackResolveProperties" AfterTargets="Publish" BeforeTargets="VelopackBuildRelease">
<PropertyGroup>
<VelopackPackVersion Condition="'$(VelopackPackVersion)' == ''">$(Version)</VelopackPackVersion>
<VelopackPackId Condition="'$(VelopackPackId)' == ''">$(AssemblyName)</VelopackPackId>
<!--<VelopackPackId Condition="'$(VelopackPackId)' == ''">$(AssemblyName)</VelopackPackId>-->
<VelopackEntryExecutableName Condition="'$(VelopackEntryExecutableName)' == ''">$(AssemblyName)</VelopackEntryExecutableName>
<VelopackPackDirectory Condition="'$(VelopackPackDirectory)' == ''">$(PublishDir)</VelopackPackDirectory>
<VelopackReleaseDirectory Condition="'$(VelopackReleaseDirectory)' == ''">Releases</VelopackReleaseDirectory>
<VelopackPackTitle Condition="'$(VelopackPackTitle)' == ''">$(Product)</VelopackPackTitle>
<VelopackPackAuthors Condition="'$(VelopackPackAuthors)' == ''">$(Authors)</VelopackPackAuthors>
<!-- TODO: Is there a way to try and determine this from the project? -->
<!--
TODO: the required runtimes can be automatically set (windows only)
We need to know the TargetFramework and the RID that's being published.
Probably we should pass these both into the C# Task and let it figure out the runtimes.
<VelopackRuntimes Condition="'$(VelopackRuntimes)' == ''">net8-x64-desktop</VelopackRuntimes>
<!-- TODO: is this a reasonable default? -->
<VelopackReleaseDirectory Condition="'$(VelopackReleaseDirectory)' == ''">releases</VelopackReleaseDirectory>
-->
</PropertyGroup>
<ConvertToAbsolutePath Paths="$(VelopackReleaseDirectory)">
@@ -49,25 +44,51 @@
<!--
TODO: Add additional error checking for the rest of the parameters.
-->
<Warning Condition="'$(VelopackPackVersion)' == ''"
<!--<Warning Condition="'$(VelopackPackVersion)' == ''"
Text="No version specified, Velopack will not publish a release."
/>
/>-->
<PackTask
Condition="'$(VelopackPackVersion)' != ''"
TargetRuntime="$(VelopackTargetRuntime)"
PackVersion="$(VelopackPackVersion)"
Runtimes="$(VelopackRuntimes)"
PackId="$(VelopackPackId)"
ReleaseDirectory="$(VelopackReleaseDirectory)"
PackDirectory="$(VelopackPackDirectory)"
PackVersion="$(VelopackPackVersion)"
/>
ReleaseDir="$(VelopackReleaseDirectory)"
PackAuthors="$(VelopackPackAuthors)"
PackTitle="$(VelopackPackTitle)"
EntryExecutableName="$(VelopackEntryExecutableName)"
Icon="$(VelopackIcon)"
ReleaseNotes="$(VelopackReleaseNotes)"
DeltaMode="$(VelopackDeltaMode)"
Channel="$(VelopackChannel)"
PackIsAppDir="$(VelopackPackIsAppDir)"
IncludePdb="$(VelopackIncludePdb)"
NoPackage="$(VelopackNoPackage)"
PackageWelcome="$(VelopackPackageWelcome)"
PackageReadme="$(VelopackPackageReadme)"
PackageLicense="$(VelopackPackageLicense)"
PackageConclusion="$(VelopackPackageConclusion)"
SigningAppIdentity="$(VelopackSigningAppIdentity)"
SigningInstallIdentity="$(VelopackSigningInstallIdentity)"
SigningEntitlements="$(VelopackSigningEntitlements)"
NotaryProfile="$(VelopackNotaryProfile)"
BundleId="$(VelopackBundleId)"
InfoPlistPath="$(VelopackInfoPlistPath)"
SplashImage="$(VelopackSplashImage)"
SkipVelopackAppCheck="$(VelopackSkipVelopackAppCheck)"
SignParameters="$(VelopackSignParameters)"
SignSkipDll="$(VelopackSignSkipDll)"
SignParallel="$(VelopackSignParallel)"
SignTemplate="$(VelopackSignTemplate)"
/>
</Target>
<Target Name="VelopackPushRelease" AfterTargets="VelopackBuildRelease" Condition="'$(VelopackPushOnPublish)' == 'true'">
<PublishTask
<PublishTask
ReleaseDirectory="$(VelopackReleaseDirectory)"
Version="$(VelopackPackVersion)"
ServiceUrl="$(VelopackFlowServiceUrl)"
/>
/>
</Target>
</Project>

View File

@@ -6,8 +6,6 @@ public class WindowsReleasifyOptions : WindowsSigningOptions
public RID TargetRuntime { get; set; }
public string Package { get; set; }
public DeltaMode DeltaMode { get; set; } = DeltaMode.BestSpeed;
public string Runtimes { get; set; }

View File

@@ -82,6 +82,8 @@ public static class HelperFile
#endif
}
public static void ClearSearchPaths() => _searchPaths.Clear();
public static void AddSearchPath(params string[] pathParts)
{
AddSearchPath(Path.Combine(pathParts));