I have two Visual Studio 2019 solutions, A and B, with both containing several projects. Solution A includes one of the projects from solution B, ProjectB, which was added to A as an existing project. This project uses several NuGet dependencies. Obviously, NuGet packages are not under source control. When a user freshly checks out the solutions from source control, here's what happens:
- If solution B is opened and built first, ProjectB's NuGet dependencies get restored as expected, and the project builds successfully.
- If solution A is opened and built after 1., everything gets built successfully. However, if step 1 is omitted, ProjectB fails to build within the scope of solution A because its referenced dependencies don't get recreated in the original path, despite NuGet having installed all the dependencies in A's
packages
folder. This results in plenty of "The referenced component could not be found" error messages, and a situation equivalent to this one.
Simply cleaning the NuGet cache doesn't help. The only thing that seems to resolve the issue is to call
Update-Package -reinstall -ProjectName ProjectB
from the solution A's Package Manager Console prior to triggering a (re)build.
I wanted to automate this by including the Update-Package
command in a pre-build event, but apparently Package Manager Console is not accessible there, and I'd like to avoid installing any other software.
Is there a way to correctly get all project dependencies restored in such case, so that the entire solution A would build from scratch automatically?