简体   繁体   中英

How to resolve nuget packages when using git submodules for VS Solution

I have two repositories. The first one is big integration repository with lots of projects in it. The second one is relatively small solution with a number of projects in it that is being developed separately and then integrated into the first solution.

I added second git repository to the first git repository as submodule, so I have such file structure:

MainSolution.sln
SomeProject1
SomeProject2
packages
my-second-project
  SecondSolution.sln
  SomeProject3
  SomeProject4

And my separate repository (after restoring nuget packages) looks like

SecondSolution.sln
SomeProject3
SomeProject4
packages

Now, each project references nuget restore packages folder separately. So None of my projects from added submodule were able to restore their nuget packages because they searched for my-second-project/packages folder which doesn't exist. And if I reinstall nuget packages, then I can see in my git diffs that they begin to reference root packages folder (like ..\\..\\packages ).

How can I resolve this?

I resolved issue by changing ..\\packages everywhere in all *.csproj files to $(SolutionDir)\\packages . Works pretty well. Simple script covers it:

find -name "*.csproj" | xargs sed -i 's/\.\.\\packages/$(SolutionDir)\\packages/g'

Don't know why nuget doesn't behave this way by default, now I need to re-run this script whenever I update/install nuget packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM