From 0e56275f94133f04354f9f36c7f85bd265607ce0 Mon Sep 17 00:00:00 2001 From: Donkey Date: Tue, 6 Aug 2024 10:36:12 +0200 Subject: [PATCH] fix(NugetServer): .library files where not supported correctly (cherry picked from commit e9a243d02a7e4729f9734e96901db5b70bc00bdd) --- .../Protocol/Nuget/BeckhoffServer.cs | 5 ++++ TwinpackShared/Protocol/Nuget/NugetServer.cs | 29 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/TwinpackShared/Protocol/Nuget/BeckhoffServer.cs b/TwinpackShared/Protocol/Nuget/BeckhoffServer.cs index 1241980..f6d5d70 100644 --- a/TwinpackShared/Protocol/Nuget/BeckhoffServer.cs +++ b/TwinpackShared/Protocol/Nuget/BeckhoffServer.cs @@ -55,5 +55,10 @@ public override async Task ResolvePackageVersionAsync library.Name = "TwinCAT.XAE.PLC.Lib." + library.Name; return await base.ResolvePackageVersionAsync(library, preferredTarget, preferredConfiguration, preferredBranch, cancellationToken); } + + protected override int EvaluateCompiled(string tags) + { + return 1; + } } } diff --git a/TwinpackShared/Protocol/Nuget/NugetServer.cs b/TwinpackShared/Protocol/Nuget/NugetServer.cs index ae6f283..63aba1d 100644 --- a/TwinpackShared/Protocol/Nuget/NugetServer.cs +++ b/TwinpackShared/Protocol/Nuget/NugetServer.cs @@ -17,6 +17,7 @@ using WixToolset.Dtf.WindowsInstaller.Package; using NuGet.Packaging.Core; using System.Data; +using EnvDTE; namespace Twinpack.Protocol { @@ -180,7 +181,7 @@ public async Task, bool>> GetPackag Branch = "main", Target = "TC3.1", Configuration = "Release", - Compiled = 1, + Compiled = EvaluateCompiled(x.Tags), //Notes =, //PackageType, Binary = null, @@ -232,8 +233,8 @@ await resource.CopyNupkgToStreamAsync( var msis = packageFiles.Where(x => x.EndsWith(".msi", StringComparison.InvariantCultureIgnoreCase)); var libraries = packageFiles.Where(x => - x.EndsWith(".library", StringComparison.InvariantCultureIgnoreCase) || - Path.GetExtension(x).StartsWith(".compiled-library")); + (packageVersion.Compiled == 0 && x.EndsWith(".library", StringComparison.InvariantCultureIgnoreCase)) || + (packageVersion.Compiled == 1 && Path.GetExtension(x).StartsWith(".compiled-library"))); if(libraries.Count() == 1) { @@ -243,7 +244,7 @@ await resource.CopyNupkgToStreamAsync( { try { - var extension = library.EndsWith(".library") ? "compiled-library" : "library"; + var extension = packageVersion.Compiled == 1 ? "compiled-library" : "library"; var filePath = $@"{cachePath ?? DefaultLibraryCachePath}\{packageVersion.Target}"; var fileName = $@"{filePath}\{packageVersion.Name}_{packageVersion.Version}.{extension}"; Directory.CreateDirectory(filePath); @@ -279,14 +280,18 @@ await resource.CopyNupkgToStreamAsync( pkg.ExtractFiles(); } - var files = Directory.GetFiles(tempFolderPath, "*", SearchOption.AllDirectories).Where(x => Path.GetExtension(x) == ".library" || Path.GetExtension(x).StartsWith(".compiled-library")); + var files = Directory.GetFiles(tempFolderPath, "*", SearchOption.AllDirectories) + .Where(x => + (packageVersion.Compiled == 0 && Path.GetExtension(x) == ".library") || + (packageVersion.Compiled == 1 && Path.GetExtension(x).StartsWith(".compiled-library"))); + if(files.Count() != 1) { throw new Exceptions.GetException("nupkg contains a msi file that contains more than one library!"); } foreach (var f in files) { - var extension = Path.GetExtension(f).StartsWith(".compiled-library") ? "compiled-library" : "library"; + var extension = packageVersion.Compiled == 1 ? "compiled-library" : "library"; var filePath = $@"{cachePath ?? DefaultLibraryCachePath}\{packageVersion.Target}"; var fileName = $@"{filePath}\{packageVersion.Name}_{packageVersion.Version}.{extension}"; Directory.CreateDirectory(filePath); @@ -302,7 +307,7 @@ await resource.CopyNupkgToStreamAsync( } else { - throw new Exceptions.GetException("nupkg should contain a single msi or library file!"); + throw new Exceptions.GetException($"nupkg should contain a single .msi or {(packageVersion.Compiled == 1 ? ".compiled-library" : ".library")} file!"); } } } @@ -374,7 +379,7 @@ public virtual async Task GetPackageVersionAsync(PlcL Branch = "main", Target = "TC3.1", Configuration = "Release", - Compiled = 1, + Compiled = EvaluateCompiled(dependency.Tags), Notes = dependency.Description, //PackageType, Binary = null, @@ -408,7 +413,7 @@ public virtual async Task GetPackageVersionAsync(PlcL Branch = "main", Target = "TC3.1", Configuration = "Release", - Compiled = 1, + Compiled = EvaluateCompiled(x.Tags), Notes = x.Description, //PackageType, Binary = null, @@ -561,5 +566,11 @@ private string EvaluateTitle(IPackageSearchMetadata x) return title; } + + protected virtual int EvaluateCompiled(string tags) + { + var tagList = tags.Split(' ').ToList(); + return tagList.IndexOf("tp-compiled-library") >= 0 ? 1 : 0; + } } }