Skip to content

Commit

Permalink
Build package from csproj file
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Mar 4, 2025
1 parent 6dd9c83 commit e0d097b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
51 changes: 46 additions & 5 deletions recipe/nuget-package.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -43,7 +43,7 @@ public class NuGetPackage : PackageDefinition

public override void BuildPackage()
{
var nugetPackSettings = new NuGetPackSettings()
var NuGetPackSettings = new NuGetPackSettings()
{
Version = PackageVersion,
BasePath = BasePath,
Expand All @@ -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!");
}
}
1 change: 1 addition & 0 deletions recipe/package-definition.cake
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public abstract class PackageDefinition

if (SymbolChecks != null)
{
Banner.Display($"Verifying {SymbolPackageName}");
// TODO: Override this in NuGetPackage
VerifySymbolPackage();
}
Expand Down

0 comments on commit e0d097b

Please sign in to comment.