Reputation: 6518
I am having a weird issue with nuget.exe command line tool.
I have a console application that launches a process which executes nuget command line tool.
Here is the output:
nuget.exe pack Project.csproj -Prop Configuration=Release
Attempting to build package from 'Project.csproj'. Packing files from
'C:\Project\bin\Release'.
It throws an Object reference not set to an instance of an object. exception.
But the way, my process WorkingDirectory is C:\Project, so the file path is ok.
What is weird is that when I use the standard windows command line, cd into the .csproj folder and execute the same command, the nupkg file is being created.
If I do:
cd ..
and runs:
nuget.exe pack Project\Project.csproj -Prop Configuration=Release
I am getting the Object reference not set to an instance of an object. exception.
My console application code is:
var process = new Process {
StartInfo = new ProcessStartInfo("nuget.exe",
"pack Project.csproj -Prop Configuration=Release")
{
WorkingDirectory = "C:\\Project",
UseShellExecute = false,
RedirectStandardInput = true,
}
};
Upvotes: 2
Views: 6841
Reputation: 6378
I think this null reference error happens because your packages.config has an entry to the assembly you no longer have.
For example, my packages.config wass like this.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="H.Common" version="1.0.0.9" targetFramework="net35" />
<package id="H.Common" version="1.0.0.10" targetFramework="net35" />
<package id="H.Validation" version="3.0.0.50" targetFramework="net35" />
</packages>
And nuget pack raised an error, as the config had a reference to a ghost assembly. I removed the line and now the config became like this.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="H.Common" version="1.0.0.10" targetFramework="net35" />
<package id="H.Validation" version="3.0.0.50" targetFramework="net35" />
</packages>
It compiles happy now.
Upvotes: 1
Reputation: 20010
I had the same issue and my problem was that after an update of an package (and a merge in SVN), the packages.config file still had both versions of the package referenced: the old and the new package. After I deleted the folder with the old package, the "Object reference not set to an instance of an object."-error popped up.
So, to solve that error, be sure that your packages.config file only has one version of a package in it.
Upvotes: 6