ProjectDependenciesGuard 0.2.0

dotnet add package ProjectDependenciesGuard --version 0.2.0
NuGet\Install-Package ProjectDependenciesGuard -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProjectDependenciesGuard" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ProjectDependenciesGuard --version 0.2.0
#r "nuget: ProjectDependenciesGuard, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ProjectDependenciesGuard as a Cake Addin
#addin nuget:?package=ProjectDependenciesGuard&version=0.2.0

// Install ProjectDependenciesGuard as a Cake Tool
#tool nuget:?package=ProjectDependenciesGuard&version=0.2.0

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

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.0 648 2/7/2023
0.1.2 252 1/28/2023