1

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?

Sam Holder
  • 32,535
  • 13
  • 101
  • 181

2 Answers2

1

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.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • This is useful info, but in my case I have only one .csproj file and there is completely no difference between this project and others in parallel folders. It even updates the packages.config files, but it doesn't update the .csproj file and I've got a broken reference. Any advice? – P.W. Feb 26 '20 at 11:42
  • Ignore my previous comment, I got fooled and I was looking at packages.config from wrong directory. The csproj was not being updated because its packages.config (the real one) had versions filled already (and it was the latest available package version). – P.W. Feb 26 '20 at 12:10
1

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.

Kevin Harker
  • 406
  • 2
  • 7
  • Yes, I had this problem as well, but I couldn't move the .sln file, so I had to add separate calls to nuget update for these projects in my update script. But it took a while to find out what's going on, it should take the projects from .sln file (it would not only avoid the problem but also save a lot of time on searching folders every time). – P.W. Feb 26 '20 at 11:45
  • @P.W. Like I mentioned in my comment, you just need to have a solution file in the root. You don't need to move your solution to the root. I agree that it should only look at projects in the solution. – Kevin Harker Sep 28 '20 at 19:24