Sam Holder
Sam Holder

Reputation: 32946

nuget command line update doesn't detect all packages.config which need to be updated

We have a build step that installs and updates the nuget packages in a solution on out build server (TeamCity). Recently this has stopped doing the updates correctly. I have investigated this and found that the problem seems to be that the update command in nuget is not updating all the projects in the soltution. I can replicate this on my local machine.

When I run this command:

.nuget\NuGet.exe update Our.Company.sln -Source http:/ourTcServer:8888/guestAuth/app/nuget/v1/FeedService.svc -RepositoryPath packages -verbosity detailed

I get this a list of 10 projects it is going to update

Found 10 projects with a packages.config file. (
Company.Project1.csproj,
Company.Project2.csproj,
Company.Project3.csproj, 
Company.Project4.csproj, 
Company.Project4.SubProject1.csproj,
Company.Project4.SubProject2.csproj,
Company.Project1.SubProject1.csproj, 
Company.Project1.SubProject2.csproj,
Company.Project2.SubProject1.csproj,         
Company.Project2.SubProject1.FurtherSubProject1.csproj)

However the solution contains 13 projects and these all contain packages.config files and as far as I can tell are no different to any of the other projects. The projects are a single project and its subprojects and our projects directory structure matches the projects names (so project1.subproject1 implies that subproject1 is in a folder inside project1) in case that is important. The projects with the issue are all in a project which has the specific names like :

Company.Something.SomethingElse.Routing
Company.Something.SomethingElse.Routing.Tests
Company.Something.SomethingElse.Routing.Tests.Specifications

In case the routing part of the name causes a problem (we had a problem before using the word Resources at the end of our package name)

We have 50+ solutions that all use the same build configuration and steps and it works fine for all of them. This solution seems to be the only one which is not updating correctly.

Does anyone know why this might be the case? Or does anyone know what the code that finds packages in a solution does which might cause it not to find some packages.config files? Or anything that might help track down this issue?

Upvotes: 1

Views: 280

Answers (2)

Kevin Harker
Kevin Harker

Reputation: 406

I found that the problem I ran into was that my projects were not in the same directory tree of the solution.

The nuget.exe update command when given solution file searches for packages.config files using the solution directory as the starting point instead of looking at each project file in the solution.

From the nuget code on GitHub:

string[] packagesConfigFiles = Directory.GetFiles(
         solutionDir, "*.config", SearchOption.AllDirectories);

You can see that they are just looking for *.config files starting in the solution directory.

My projects and solutions are organized like this:

/Libraries/Shared/Shared.csproj
/Programs/NTService/NTService.csproj
/Programs/NTService.sln

In this case, if I run update on the NTService.sln file it will only update the NTService.csproj references because it is in the same directory tree as the NTService.sln file.

Since it just looks at all packages in the whole tree, I just put a solution file at the root of my repository and then run the update on that. It doesn't matter what projects are in that solution file.

Upvotes: 1

Sam Holder
Sam Holder

Reputation: 32946

Ok so the issue was that we had renamed some of our projects and so the .csproj files and had not removed to old, unused project files and nuget has a piece of code which finds the projectfile into which it it going to update the references of the updated packages. It does this by finding all the files which are .csproj (or whatever project file flavour you are using) in the same directory as the packages.config. If this does not result in exactly 1 file then it throws an exception, which is subsequently caught and ignored and nothing is logged, so you are non the wiser.

Hopefully this will help someone else in the future. Maybe me.

Upvotes: 1

Related Questions