Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build package from csproj file #60

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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