-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Coming from the Java world I am used to be able to specify library dependencies and their version in some kind of parent project config file, which will then be applied to all child projects.
It seems that I can specify a <PackageReference>
in a Directory.Build.props
file in my solution directory, which will cause every project in that solution to import the <PackageReference>
, as well.
This is great if you want to add a dependency to all your projects. Maybe a logging dependency.
But often only a subset of child projects needs a dependency but you still want all those projects to use the same version of that dependency. Firstly, to be sure that a "compatible" version is used in the child projects, and secondly, to be able to easily update the dependency version for all projects that use the dependency.
For example, you want all your Xyz.Test projects, which contain tests, to use the same version of your test framework. But not all projects are test projects and thus not all of them need a dependency to a test framework.
In Maven I would specify a <dependencyManagement>
section in the parent pom.xml, where I would define dependencies' name and version.
In a child pom.xml I would then only add the dependency name without specifying a version.
The version will be taken from the parent pom.xml's <dependencyManagement>
section.
If I specify a version in the child pom.xml, it will overwrite the version set in the parent pom.xml.
If I don't add the dependency name to the child pom.xml, it does not include the dependency at all.
How can I achieve the same in dotnet and the .csproj files?