I have a common library that I want to share between a few solutions, that stored in different github repositories. We put the shared library in separate GitHub repository and created nuget package, that can be installed in each required projects/solution. The disadvantage is that changing code in a library involves a few steps ( change code, push to library repository, creating nuget package, installing package) which is annoying.
I wanted to use git subtree
to create sub directory with library project and use it as local project in my solution with easy code changing/testing/debugging.
Developers of "Main" solutions will have a choice- include library as a binary nuget package or as a source project in subdirectory.
PROBLEM: When I tried git subtree
, I found one issue: csproj files have relative references to packages folder, that are located on different levels, when included in standalone library solution and when included in a main solution.
When in MyLib.sln the path is "..\Packages" , but in Main.sln the path should be "..\..\Packages" .
The structure of Main GitHub Repository ( and OtherUserOfMyLib GitHub Repository(is)) :
Main.sln
LibSubfolder
-----------------| MyLib.sln
-----------------| MyLibSource
--------------------------| myLib.csproj
--------------------------| myLib code
-----------------| (expected Packages from lib solution)
Packages. (From main solution)
The structure of MyLib GitHub Repository:
MyLib.sln
MyLibSource
--------------| myLib.csproj
--------------| myLib code
Packages. (From lib solution)
I tried git subtree
to copy only MyLibSource subdirectory from Lib repository (That will allow to have relative position of packages folder the same). Unfortunately I didn't find a way to to copy subdirectory from another repo, that support later PUSH the changes back to original repo. The answer
Add subdirectory of remote repo with git-subtree has a few options, but all of them seems only discussed one-way (pull) syncronization.
From what I looked, git submodule and git subrepo do not support copying subfolder from source repository.
Am I missing something? Can anyone suggest, how to copy to subfolder of my repository folder from library repository, that will allow later two-way (pull/push) syncronization?
Other option I considered is to change the location of packages folder. But I am not sure, which path to choose to be consistent for both main.sln and MyLib.sln.
The third approach is do not use MyLib.sln in MyLib repository ; use the repository only as a master storage for library source code. Instead create MyLib.sln in the Main repository and use it to build NuGet package. I will be able to use git subtree pull/push content of MyLibSource project. OtherUserOfMyLib repositories will just refer to the project in subfolder and also call git subtree pull/push when required
Main.sln
MyLib.sln ( locate in Main repository instead of MyLib repository)
LibSubfolder
-----------------| MyLibSource
--------------------------| myLib.csproj
--------------------------| myLib code
Packages
My question is which approach to try:
- spend time trying to find a way to push back git subtree created subfolder?
- try to change location of packages folder?
- Keep solution to build nuget package outside of repository having the package(3rd approach)?
- anything else?
I've looked at similar questions like Best practice to share common libraries between solutions in .NET and How do you share code between projects/solutions in Visual Studio? but didn't find satisfactory solutions.