From e0d097b71cd53571b8429eb8bf9aa125b2c3c060 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Tue, 4 Mar 2025 10:41:29 -0800 Subject: [PATCH] Build package from csproj file --- recipe/nuget-package.cake | 51 ++++++++++++++++++++++++++++++---- recipe/package-definition.cake | 1 + 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/recipe/nuget-package.cake b/recipe/nuget-package.cake index 636db60..70f7794 100644 --- a/recipe/nuget-package.cake +++ b/recipe/nuget-package.cake @@ -20,8 +20,8 @@ public class NuGetPackage : PackageDefinition symbols: symbols, tests: tests) { - if (!source.EndsWith(".nuspec")) - throw new ArgumentException("Source must be a nuspec file", nameof(source)); + //if (!source.EndsWith(".nuspec")) + // throw new ArgumentException("Source must be a nuspec file", nameof(source)); if (symbols != null) { @@ -43,7 +43,7 @@ public class NuGetPackage : PackageDefinition public override void BuildPackage() { - var nugetPackSettings = new NuGetPackSettings() + var NuGetPackSettings = new NuGetPackSettings() { Version = PackageVersion, BasePath = BasePath, @@ -54,8 +54,49 @@ public class NuGetPackage : PackageDefinition }; if (HasSymbols) - nugetPackSettings.SymbolPackageFormat = "snupkg"; + NuGetPackSettings.SymbolPackageFormat = "snupkg"; - _context.NuGetPack(PackageSource, nugetPackSettings); + if (string.IsNullOrEmpty(PackageSource)) + _context.NuGetPack(NuGetPackSettings); + else if (PackageSource.EndsWith(".nuspec")) + _context.NuGetPack(PackageSource, NuGetPackSettings); + else if (PackageSource.EndsWith(".csproj")) + _context.MSBuild(PackageSource, + new MSBuildSettings + { + Target = "pack", + Verbosity = BuildSettings.MSBuildVerbosity, + Configuration = BuildSettings.Configuration, + PlatformTarget = PlatformTarget.MSIL, + //AllowPreviewVersion = BuildSettings.MSBuildAllowPreviewVersion + }.WithProperty("Version", BuildSettings.PackageVersion)); + else + throw new ArgumentException( + $"Invalid package source specified: {PackageSource}", "source"); + } + + public override void VerifySymbolPackage() + { + if (!SIO.File.Exists(BuildSettings.PackageDirectory + SymbolPackageName)) + { + _context.Error($" ERROR: File {SymbolPackageName} was not found."); + throw new Exception("Verification Failed!"); + } + + string tempDir = SIO.Directory.CreateTempSubdirectory().FullName; + _context.Unzip(BuildSettings.PackageDirectory + SymbolPackageName, tempDir); + + bool allOK = true; + + if (allOK && SymbolChecks != null) + foreach (var check in SymbolChecks) + allOK &= check.ApplyTo(tempDir); + + SIO.Directory.Delete(tempDir, true); + + if (allOK) + Console.WriteLine("All checks passed!"); + else + throw new Exception("Verification failed!"); } } diff --git a/recipe/package-definition.cake b/recipe/package-definition.cake index ea9ff54..4732446 100644 --- a/recipe/package-definition.cake +++ b/recipe/package-definition.cake @@ -141,6 +141,7 @@ public abstract class PackageDefinition if (SymbolChecks != null) { + Banner.Display($"Verifying {SymbolPackageName}"); // TODO: Override this in NuGetPackage VerifySymbolPackage(); }