2
Vote

Multiple .csproj files in Project directory cause Nuget.exe update to fail

description

If there are more than one .csproj in the same project directory when running an update via nuget.exe, the following error is received.:

C:\Users\ben\Documents\Visual Studio 2010\Projects\ConsoleApplication2>nuget update ConsoleApplication1\packages.config

Unable to locate project file for 'C:\Users\ben\Documents\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication1\packages.config'.

C:\Users\ben\Documents\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication1>dir
Volume in drive C has no label.
Volume Serial Number is 6C96-0252

Directory of C:\Users\ben\Documents\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication1

08/07/2011 09:42 PM <DIR> .
08/07/2011 09:42 PM <DIR> ..
08/07/2011 04:42 PM <DIR> bin
08/07/2011 09:17 PM 3,097 ConsoleApplication1 - Copy.csproj
08/07/2011 09:35 PM 3,097 ConsoleApplication1.csproj
08/07/2011 04:42 PM <DIR> obj
08/07/2011 04:52 PM 163 packages - Copy.config
08/07/2011 09:05 PM 163 packages.config
08/07/2011 04:37 PM 228 Program.cs
08/07/2011 04:42 PM <DIR> Properties
           5 File(s)          6,748 bytes
           5 Dir(s)  22,533,255,168 bytes free
Appears to be by Design:

NuGet.Common.ProjectHelper:
    public static bool TryGetProjectFile(string directory, out string projectFile) {
        projectFile = null;
        var files = Directory.GetFiles(directory);

        var candidates = files.Where(file => _supportedProjectExtensions.Contains(Path.GetExtension(file)))
                              .ToList();

        switch (candidates.Count) {
            case 1:
                projectFile = candidates.Single();
                break;
        }

        return !String.IsNullOrEmpty(projectFile);
    }
Should this be using the solution file to identify the correct project rather than just picking the fist project file in a directory with a packages.config?

comments

dfowler wrote Aug 8, 2011 at 4:58 AM

This will be fixed as part of http://nuget.codeplex.com/workitem/1272

FilipDeVos wrote Oct 4, 2013 at 9:59 AM

This is fixed in the context of this issue https://nuget.codeplex.com/workitem/3538