NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Pack doesn't respect SolutionDir from commandline to look for packages if there are more than one sln files in the folder hierarchy #6595

Open anangaur opened 6 years ago

anangaur commented 6 years ago

From Paulo on mail:

I have a project that has a dependency on Newtonsoft.Json version 10.0.3 and compiles just fine.

However, nuget pack throws this error:

Found packages.config. Using packages listed as dependencies NuGet.CommandLine.CommandLineException: Unable to find 'Newtonsoft.Json.10.0.3.nupkg'. Make sure the project has been built. at NuGet.CommandLine.ProjectFactory.AddDependencies(Dictionary`2 packagesAndDependencies) at NuGet.CommandLine.ProjectFactory.ProcessDependencies(PackageBuilder builder) at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder) at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path) at NuGet.CommandLine.PackCommand.ExecuteCommand() at NuGet.CommandLine.Command.ExecuteCommandAsync() at NuGet.CommandLine.Command.Execute() at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

This also happens with other projects.

What am I missing?

mishra14 commented 6 years ago

cc @rohit21agrawal

paulomorgado commented 6 years ago

I'm Paulo.

rohit21agrawal commented 6 years ago

@paulomorgado does the newtonsoft.json nupkg exist in the solution packages folder on disk?

paulomorgado commented 6 years ago

As far as I can tell, yes. It's where the project itself picking it for referencing.

This is happening with version 4.1.0.2450 of nuget.exe.

If you point me to the commit for this version, I could try to debug it.

paulomorgado commented 6 years ago

As far as I can tell, yes! But NuGet.exe is not telling me where it's looking for it.

paulomorgado commented 6 years ago

I've tried with the latest version (nuget.exe 4.5.1) and the issue seems to have been resolved.

Nevertheless, when I choose verbosity detailed, the error message should mention the full path of what's looking for.

paulomorgado commented 6 years ago

OOPS! Looks like it's back with 4.5.1.

The detailed output is:

Found packages.config. Using packages listed as dependencies
Unable to find 'Newtonsoft.Json.10.0.3.nupkg'. Make sure the project has been built.
NuGet.CommandLine.CommandLineException: Unable to find 'Newtonsoft.Json.10.0.3.nupkg'. Make sure the project has been built.
   at NuGet.CommandLine.ProjectFactory.AddDependencies(Dictionary`2 packagesAndDependencies)
   at NuGet.CommandLine.ProjectFactory.RecursivelyApply(Action`1 action, Object alreadyAppliedProjects)
   at NuGet.CommandLine.ProjectFactory.RecursivelyApply(Action`1 action)
   at NuGet.CommandLine.ProjectFactory.ProcessDependencies(PackageBuilder builder)
   at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
   at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
   at NuGet.CommandLine.PackCommand.ExecuteCommand()
   at NuGet.CommandLine.Command.ExecuteCommandAsync()
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

I tried using ProcMon to get where nuget.exe is trying to retrieve 'Newtonsoft.Json.10.0.3.nupkg' from and there's no mention of it in the capture.

nuget.exe tries to access "\src\packages" and the project is at "\src\" and the packages directory is "\packages".

Is there anything else I can look at?

anangaur commented 6 years ago

@rohit21agrawal will setting the NUGET_PACKAGES env variable explicitly help? Does pack respect the env variable or command line option to state where the packages are?

paulomorgado commented 6 years ago

Nope!

NuGet Version: 4.5.1.4879
Attempting to build package from '<project>.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin\amd64'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from '<build dir>\output\GateCommon\Release'.
Using '<package>.nuspec' for metadata.
Add file '<build dir>\<project>\Release\VisionBox.Gate.GateCommon.dll' to package as 'lib\net462\VisionBox.Gate.GateCommon.dll'
Found packages.config. Using packages listed as dependencies
Unable to find 'EntityFramework.6.1.3.nupkg'. Make sure the project has been built.
NuGet.CommandLine.CommandLineException: Unable to find 'EntityFramework.6.1.3.nupkg'. Make sure the project has been built.
   at NuGet.CommandLine.ProjectFactory.AddDependencies(Dictionary`2 packagesAndDependencies)
   at NuGet.CommandLine.ProjectFactory.RecursivelyApply(Action`1 action, Object alreadyAppliedProjects)
   at NuGet.CommandLine.ProjectFactory.RecursivelyApply(Action`1 action)
   at NuGet.CommandLine.ProjectFactory.ProcessDependencies(PackageBuilder builder)
   at NuGet.CommandLine.ProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder)
   at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
   at NuGet.CommandLine.PackCommand.ExecuteCommand()
   at NuGet.CommandLine.Command.ExecuteCommandAsync()
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

Contents of NUGET_PACKAGES:

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         2/23/2018   9:36 AM            EntityFramework.6.1.3
d----         2/23/2018   9:36 AM            Newtonsoft.Json.10.0.3
d----         2/23/2018   9:36 AM            Newtonsoft.Json.9.0.1
d----         2/23/2018   9:36 AM            protobuf-net.2.3.3
d----         2/23/2018   9:36 AM            RabbitMQ.Client.4.1.3
d----         2/23/2018   9:36 AM            System.Runtime.Numerics.4.3.0
...
paulomorgado commented 6 years ago

After making a custom build with more detailed logging, I found out that NuGet.exe is trying to find the packages in \<solution dir>\src instead of \<solution dir> even when NUGET_PACKAGES is set to \<solution dir>.

Why? I don't know!

rohit21agrawal commented 6 years ago

is there a repro project/solution you can attach for us to investigate this?

paulomorgado commented 6 years ago

I'm afraid I can't.

I'll try adding more logging to find out where nuget.exe is loosing the correct solution dir.

paulomorgado commented 6 years ago

Running from \<solution dir>, NuGet.Commands.PackCommandRunner.BuildFromProjectFile is being called with \<solution dir>\src\<project dir>\<project file> for path. NuGet.CommandLine.ProjectFactory.CreateBuilder is being called with null for basePath.

paulomorgado commented 6 years ago

Found the source of the problem. There's a solution in the \src folder and there seems to be no way to override it.

rohit21agrawal commented 6 years ago

Can you pass -Properties SolutionDir= <actual solution dir> from the command line?

paulomorgado commented 6 years ago

The only difference was that I had this warning:

WARNING: NU5114: 'SolutionDir' key already exists in Properties collection. Overriding value.

But it's still not looking into that folder.

If I remove all .sln files in subfolders, NuGet pack works just fine.