Home > OS >  c# multi-project solution managing dependencies
c# multi-project solution managing dependencies

Time:06-13

I'm using Scala with SBT where I can define my dependencies in a separate file and reference them in the project's main build file (see: https://www.scala-sbt.org/1.x/docs/Scala-Files-Example.html)

My question is how can I manage dependencies in C# between multiple projects in a similar manner? My main problem is that when I want to go through my dependencies I can't see what project uses what and I need to update scattered dependencies throughout multiple csproj files.

My best idea right now is to create shared projects where I define common dependencies and reference these projects as projectreferences. (for example both project A and B needs dependency X, I don't want to define that dependency in both projects because I want to bump the version of that dependency globally in my solution, so I create a third project, project C, reference dependency X in that project and reference C in A & B, but this would create a lot of empty projects just to manage dependencies and I feel like there should be a better way of dealing with this problem)

(PS: I'm using vscode & omnisharp, VS's nice nuget manager is not an option)

CodePudding user response:

A Directory.Build.props file is the rough equivalent in .NET https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022#directorybuildprops-and-directorybuildtargets

You add references to dependencies there, and they will be picked up by all project files under it in the directory structure

  • Related