Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cake NuGetPack Configuration

I'm trying to create a NuGet package using a Cake script:

var configuration = Argument("configuration", "Release");

var binDir = Directory("./bin") ;
var nugetPackageDir = Directory("./artifacts");

var nugetFilePaths = GetFiles("./**/*.csproj").Concat(GetFiles("./**/*.nuspec"));

var nuGetPackSettings = new NuGetPackSettings
{   
  BasePath = binDir + Directory(configuration),
  OutputDirectory = nugetPackageDir  
};

Task("NuGetPack")
  .Does(() => NuGetPack(nugetFilePaths, nuGetPackSettings));

I get the following error:

========================================
NuGetPack
========================================
Executing task: NuGetPack
Attempting to build package from 'SomeProject.csproj'.
MSBuild auto-detection: using msbuild version '12.0' from 'C:\Program Files (x86)\MSBuild\12.0\bin'.
Unable to find 'C:\DEV\SomeProject\bin\Debug\SomeProject.dll'. Make sure the project has been built.
An error occured when executing task 'NuGetPack'.
Error: NuGet: Process returned an error (exit code 1).

It searches the assembly in the Debug folder instead of the Release folder. How to set NuGetPack build configuration to Release in Cake?

like image 923
Daniel Matac Avatar asked Jun 14 '16 14:06

Daniel Matac


2 Answers

You need to add the following command line argument -Prop Configuration=Release to the nuget pack command:

var nuGetPackSettings = new NuGetPackSettings
{   
  BasePath = binDir + Directory(configuration),
  OutputDirectory = nugetPackageDir,
  ArgumentCustomization = args => args.Append("-Prop Configuration=" + configuration)
};
like image 69
Daniel Matac Avatar answered Oct 28 '22 07:10

Daniel Matac


It can be set using the Properties property:

var nuGetPackSettings = new NuGetPackSettings
{
  BasePath = binDir + Directory(configuration),
  OutputDirectory = nugetPackageDir,
  Properties = new Dictionary<string, string>
  {
    { "Configuration", configuration }
  }
};
like image 29
phehr Avatar answered Oct 28 '22 05:10

phehr