Adding netstandard 2.0 support for packaging projects

Minor code cleanup and spelling fixes
This commit is contained in:
Kevin Bost
2024-01-28 21:30:39 -08:00
parent 80efd49e1b
commit 217055b896
21 changed files with 48 additions and 53 deletions

View File

@@ -135,13 +135,13 @@ jobs:
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: ${{ runner.os }}-nuget- restore-keys: ${{ runner.os }}-nuget-
- name: Download Rust Windows - name: Download Rust OSX
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: rust-macos-latest name: rust-macos-latest
path: src/Rust/target/release path: src/Rust/target/release
- name: Download Rust OSX - name: Download Rust Windows
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: rust-windows-latest name: rust-windows-latest

View File

@@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31815.197 VisualStudioVersion = 17.0.31815.197
@@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionLevel", "SolutionLe
.editorconfig = .editorconfig .editorconfig = .editorconfig
.github\workflows\build.yml = .github\workflows\build.yml .github\workflows\build.yml = .github\workflows\build.yml
src\Directory.Build.props = src\Directory.Build.props src\Directory.Build.props = src\Directory.Build.props
test\Directory.Build.props = test\Directory.Build.props
nuget.config = nuget.config nuget.config = nuget.config
README.md = README.md README.md = README.md
Velopack.entitlements = Velopack.entitlements Velopack.entitlements = Velopack.entitlements
@@ -26,6 +25,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Velopack.CommandLine.Tests", "test\Velopack.CommandLine.Tests\Velopack.CommandLine.Tests.csproj", "{519EAB50-47B8-425F-8B20-AB9548F220B4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Velopack.CommandLine.Tests", "test\Velopack.CommandLine.Tests\Velopack.CommandLine.Tests.csproj", "{519EAB50-47B8-425F-8B20-AB9548F220B4}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7AC3A776-B582-4B65-9D03-BD52332B5CA3}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7AC3A776-B582-4B65-9D03-BD52332B5CA3}"
ProjectSection(SolutionItems) = preProject
test\Directory.Build.props = test\Directory.Build.props
EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Velopack.Packaging.Windows", "src\Velopack.Packaging.Windows\Velopack.Packaging.Windows.csproj", "{E35039C8-1F98-48EB-B7D5-08E33DF061A7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Velopack.Packaging.Windows", "src\Velopack.Packaging.Windows\Velopack.Packaging.Windows.csproj", "{E35039C8-1F98-48EB-B7D5-08E33DF061A7}"
EndProject EndProject

View File

@@ -1,4 +1,9 @@
@echo off @echo off
REM This script requires several tools to be installed for it to work:
REM cargo (rust): winget install Rustlang.Rustup
REM Nerdbank.GitVersioning (nbgv): dotnet tool install --global nbgv
REM C++ Build Tools, typically installed via "Desktop development with C++" workload.
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
if "%~1"=="" ( if "%~1"=="" (

View File

@@ -64,7 +64,7 @@ public abstract class DownRepository<TDown> : IRepositoryCanDownload<TDown>
var latest = releases.Where(r => r.Type == VelopackAssetType.Full).OrderByDescending(r => r.Version).FirstOrDefault(); var latest = releases.Where(r => r.Type == VelopackAssetType.Full).OrderByDescending(r => r.Version).FirstOrDefault();
if (latest == null) { if (latest == null) {
Log.Warn("No full / applicible release was found to download. Aborting."); Log.Warn("No full / applicable release was found to download. Aborting.");
return; return;
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);CA2007;CS8002</NoWarn> <NoWarn>$(NoWarn);CA2007;CS8002</NoWarn>
</PropertyGroup> </PropertyGroup>

View File

@@ -204,7 +204,7 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
var helper = new CodeSign(Log); var helper = new CodeSign(Log);
if (string.IsNullOrEmpty(signParams) && string.IsNullOrEmpty(signTemplate)) { if (string.IsNullOrEmpty(signParams) && string.IsNullOrEmpty(signTemplate)) {
Log.Warn($"No signing paramaters provided, {filePaths.Length} file(s) will not be signed."); Log.Warn($"No signing parameters provided, {filePaths.Length} file(s) will not be signed.");
return; return;
} }

View File

@@ -1,12 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.NET.HostModel.AppHost; using Microsoft.NET.HostModel.AppHost;

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2007;CS8002</NoWarn> <NoWarn>$(NoWarn);CA2007;CS8002</NoWarn>
@@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AsmResolver.DotNet" Version="5.5.0" /> <PackageReference Include="AsmResolver.DotNet" Version="5.5.0" />
<PackageReference Include="AsmResolver.PE.Win32Resources" Version="5.5.0" /> <PackageReference Include="AsmResolver.PE.Win32Resources" Version="5.5.0" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,10 +1,4 @@
using System; using Velopack.Json;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Velopack.Json;
using Velopack.Packaging.Exceptions; using Velopack.Packaging.Exceptions;
namespace Velopack.Packaging namespace Velopack.Packaging
@@ -26,7 +20,7 @@ namespace Velopack.Packaging
Files = files.OrderBy(f => f).ToList(), Files = files.OrderBy(f => f).ToList(),
}; };
var path = Path.Combine(outputDir, $"assets.{channel}.json"); var path = Path.Combine(outputDir, $"assets.{channel}.json");
var json = JsonSerializer.Serialize(assets, SimpleJson.Options); var json = SimpleJson.SerializeObject(assets);
File.WriteAllText(path, json); File.WriteAllText(path, json);
} }
@@ -37,7 +31,7 @@ namespace Velopack.Packaging
throw new UserInfoException($"Could not find assets file for channel '{channel}' (looking for '{Path.GetFileName(path)}' in directory '{outputDir}'). " + throw new UserInfoException($"Could not find assets file for channel '{channel}' (looking for '{Path.GetFileName(path)}' in directory '{outputDir}'). " +
$"If you've just created a Velopack release, verify you're calling this command with the same '--channel' as you did with 'pack'."); $"If you've just created a Velopack release, verify you're calling this command with the same '--channel' as you did with 'pack'.");
} }
return JsonSerializer.Deserialize<BuildAssets>(File.ReadAllText(path), SimpleJson.Options); return SimpleJson.DeserializeObject<BuildAssets>(File.ReadAllText(path));
} }
} }
} }

View File

@@ -1,6 +1,4 @@
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Intrinsics.Arm;
using System.Text; using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack.Compression; using Velopack.Compression;

View File

@@ -153,7 +153,12 @@ namespace Velopack.Packaging
} }
foreach (var f in filesToCopy) { foreach (var f in filesToCopy) {
#if NET6_0_OR_GREATER
File.Move(f.from, f.to, true); File.Move(f.from, f.to, true);
#else
File.Delete(f.to);
File.Move(f.from, f.to);
#endif
} }
ReleaseEntryHelper.UpdateReleaseFiles(releaseDir.FullName, Log); ReleaseEntryHelper.UpdateReleaseFiles(releaseDir.FullName, Log);

View File

@@ -1,12 +1,8 @@
using System.Text.Json; using Microsoft.Extensions.Logging;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Json; using Velopack.Json;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Packaging.Exceptions; using Velopack.Packaging.Exceptions;
using Velopack.Sources;
namespace Velopack.Packaging namespace Velopack.Packaging
{ {
@@ -123,12 +119,16 @@ namespace Velopack.Packaging
public static IEnumerable<VelopackAsset> MergeAssets(IEnumerable<VelopackAsset> priority, IEnumerable<VelopackAsset> secondary) public static IEnumerable<VelopackAsset> MergeAssets(IEnumerable<VelopackAsset> priority, IEnumerable<VelopackAsset> secondary)
{ {
#if NET6_0_OR_GREATER
return priority.Concat(secondary).DistinctBy(x => x.FileName); return priority.Concat(secondary).DistinctBy(x => x.FileName);
#else
return priority.Concat(secondary).GroupBy(x => x.FileName).Select(g => g.First());
#endif
} }
public static string GetAssetFeedJson(VelopackAssetFeed feed) public static string GetAssetFeedJson(VelopackAssetFeed feed)
{ {
return JsonSerializer.Serialize(feed, SimpleJson.Options); return SimpleJson.SerializeObject(feed);
} }
public static string GetSuggestedReleaseName(string id, string version, string channel, bool delta) public static string GetSuggestedReleaseName(string id, string version, string channel, bool delta)

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);CA2007;CS8002</NoWarn> <NoWarn>$(NoWarn);CA2007;CS8002</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

View File

@@ -2,7 +2,7 @@
public class BaseCommand : CliCommand public class BaseCommand : CliCommand
{ {
private Dictionary<CliOption, Action<ParseResult>> _setters = new(); private readonly Dictionary<CliOption, Action<ParseResult>> _setters = new();
protected BaseCommand(string name, string description) protected BaseCommand(string name, string description)
: base(name, description) : base(name, description)
@@ -40,7 +40,7 @@ public class BaseCommand : CliCommand
public virtual ParseResult ParseAndApply(string command) public virtual ParseResult ParseAndApply(string command)
{ {
var x = this.Parse(command); var x = Parse(command);
SetProperties(x); SetProperties(x);
return x; return x;
} }

View File

@@ -1,10 +1,4 @@
using System; using Velopack.Packaging.Abstractions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spectre.Console;
using Velopack.Packaging.Abstractions;
namespace Velopack.Vpk.Logging namespace Velopack.Vpk.Logging
{ {

View File

@@ -57,10 +57,10 @@ namespace Velopack.Locators
ourExePath = Path.GetFullPath(ourExePath); ourExePath = Path.GetFullPath(ourExePath);
string myDirPath = Path.GetDirectoryName(ourExePath)!; string myDirPath = Path.GetDirectoryName(ourExePath)!;
var myDirName = Path.GetFileName(myDirPath); var myDirName = Path.GetFileName(myDirPath);
var possibleUpdateExe = Path.GetFullPath(Path.Combine(myDirPath, "..\\Update.exe")); var possibleUpdateExe = Path.GetFullPath(Path.Combine(myDirPath, "..", "Update.exe"));
var ixCurrent = ourExePath.LastIndexOf("/current/", StringComparison.InvariantCultureIgnoreCase); var ixCurrent = ourExePath.LastIndexOf("/current/", StringComparison.InvariantCultureIgnoreCase);
Log.Info($"Initialising {nameof(WindowsVelopackLocator)}"); Log.Info($"Initializing {nameof(WindowsVelopackLocator)}");
if (File.Exists(possibleUpdateExe)) { if (File.Exists(possibleUpdateExe)) {
Log.Info("Update.exe found in parent directory"); Log.Info("Update.exe found in parent directory");

View File

@@ -163,7 +163,7 @@ namespace Velopack
///// <summary> ///// <summary>
///// Given a local directory containing a package corresponding to this release, returns the ///// Given a local directory containing a package corresponding to this release, returns the
///// correspoding release notes from within the package. ///// corresponding release notes from within the package.
///// </summary> ///// </summary>
//public string GetReleaseNotes(string packageDirectory, ReleaseNotesFormat format) //public string GetReleaseNotes(string packageDirectory, ReleaseNotesFormat format)
//{ //{
@@ -294,7 +294,7 @@ namespace Velopack
/// <summary> /// <summary>
/// Parse the contents of a RELEASES file into a list of <see cref="ReleaseEntry"/>'s, /// Parse the contents of a RELEASES file into a list of <see cref="ReleaseEntry"/>'s,
/// with any staging-uneligible releases removed. /// with any staging-ineligible releases removed.
/// </summary> /// </summary>
public static IEnumerable<ReleaseEntry> ParseReleaseFileAndApplyStaging(string fileContents, Guid? userToken) public static IEnumerable<ReleaseEntry> ParseReleaseFileAndApplyStaging(string fileContents, Guid? userToken)
{ {

View File

@@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Velopack.Sources namespace Velopack.Sources
{ {

View File

@@ -68,11 +68,13 @@ namespace Velopack
var p = Process.Start(psi); var p = Process.Start(psi);
try { if (p is not null) {
// this is an attempt to work around a bug where the restarted app fails to come to foreground. try {
AllowSetForegroundWindow(p.Id); // this is an attempt to work around a bug where the restarted app fails to come to foreground.
} catch (Exception ex) { AllowSetForegroundWindow(p.Id);
logger.LogWarning(ex, "Failed to allow Update.exe to set foreground window."); } catch (Exception ex) {
logger.LogWarning(ex, "Failed to allow Update.exe to set foreground window.");
}
} }
Thread.Sleep(300); Thread.Sleep(300);

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;

View File

@@ -26,7 +26,7 @@ namespace Velopack
/// <summary> /// <summary>
/// A list of assets available in this feed. /// A list of assets available in this feed.
/// </summary> /// </summary>
public VelopackAsset[] Assets { get; init; } = new VelopackAsset[0]; public VelopackAsset[] Assets { get; init; } = Array.Empty<VelopackAsset>();
/// <summary> /// <summary>
/// Parse a json string into a <see cref="VelopackAssetFeed"/>. /// Parse a json string into a <see cref="VelopackAssetFeed"/>.