ProjectDependenciesGuard 0.1.2
See the version list below for details.
dotnet add package ProjectDependenciesGuard --version 0.1.2
NuGet\Install-Package ProjectDependenciesGuard -Version 0.1.2
<PackageReference Include="ProjectDependenciesGuard" Version="0.1.2" />
paket add ProjectDependenciesGuard --version 0.1.2
#r "nuget: ProjectDependenciesGuard, 0.1.2"
// Install ProjectDependenciesGuard as a Cake Addin #addin nuget:?package=ProjectDependenciesGuard&version=0.1.2 // Install ProjectDependenciesGuard as a Cake Tool #tool nuget:?package=ProjectDependenciesGuard&version=0.1.2
ProjectDependenciesGuard
A fluent API for .NET Standard 2.1 that can be used in unit tests to:
- Enforce project and package dependencies rules.
- Find duplicate transitive dependencies.
Usage
// Projects found in directory and subdirectories should not have transitive dependencies. Since relative path is used, existence of file TestApp.sln is checked to ensure resulting rooted path is correct.
var result = DependencyGuard.ProjectsAndPackagesInPath(@"..\..\..\..\..\..\TestApp", "TestApp.sln")
.Should()
.NotHaveDuplicateTransitiveDependencies()
.GetResult();
// Projects found in directory and subdirectories that have a name containing ".Contract." should only depend on packages
var result = DependencyGuard.ProjectsAndPackagesInPath(@"..\..\..\..\..\..\TestApp")
.That()
.MatchPredicate(q => q.Name.Contains(".Contract.") && q.CodeSetType == CodeSetType.Project)
.Should()
.OnlyDependOnSetsMatchingPredicate((testedProject, dependency) => dependency.CodeSetType == CodeSetType.Package).GetResult();
Rationale
This project was inspired by a session of code refactoring where I found and removed dozens of duplicate transitive dependencies between projects. Before starting this project I examined several existing options.
I was looking for a solution that could:
- Examine dependencies declared in csproj files.
- Find duplicate transitive dependencies between solution projects and packages.
- Enforce rules for project and package dependencies. For example check if projects with name containing string ".Contract." have no dependency on other projects in solution.
Existing options examined:
- NDepend
- Looks at compiled code structure, not declared dependencies.
- Snitch
- Looks only at NuGet packages. Dependencies on projects are not considered.
- NetArchTest
- Looks at compiled code structure, not declared dependencies.
- DependenSee
- Designed for visualization of declared dependencies as a graph. Not for enforcing rules.
Since I have not found what I was looking for, I decided to create my own solution. For references discovery I used code from DependenSee project. Desing of fluent API was heavily influenced by NetArchTest project.
Limitations
- Currently only traverses csproj and vbproj files. No other file types are supported.
Powered by
- Reference discovery service from DependenSee
- Heavily influenced by NetArchTest
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- QuikGraph (>= 2.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.