NDepend - Improved Dependency Graph Feature

Introduction

This is another post related to the NDepend tool and Code Quality for .NET Core application follow by this

NDepend makes .NET code beautiful by measuring quality with metrics, generate diagrams, and enforce decisions with code rules, right in Visual Studio.

I have used this tool for analyzing the .NET Core project and it is a great and intuitive tool to work with. The new version NDepend  v2020.1.0 is available with the latest features e.g.  Dependency Graph Completely Rebuilt

What is new with the Dependency Graph

I have also used the Dependency Graph in the previous version of the NDepend. It was much useful to identify the dependency between the different assemblies in the solution.

This time the NDepend team improvise this feature and restructured to analyze large project architecture. Below features make it easy to analyze using the dependency graph.

New navigation system

You can drag and drop from Visual Studio solution explorer, Expand/Collapse parent elements, Search elements in graphs by name with the search windows, also provided Undo / Redo feature.

New layout options

  • Group-By Assemblies, Namespaces, Types, Clusters Filters to show or hide
  • Box size proportional to element size, Edge width proportional to the coupling strength
  • Color conventions instantly identify caller/callee elements
  • Complex graph simplified with Clusters
  • Export to SVG vector format or PNG bitmap format.

Let's explorer that how can we generate Dependency Graph by taking an example of the OrchardCore application which contains more than 143 projects. 

Open the application in the Visual Studio and create an NDepend project by attached to the Visual Studio solution.

Filter and select the project that you want to analyze.

Now a dialog box will open with options, View NDepend Dashboard, Show NDepend Interactive Dependency Graph. Click on the "Show NDepend Interactive Dependency Graph" button to see the dependency graph.

After a few seconds windows will open which is shown in the image below. It has the relationship between the projects and their dependencies.

You can also zoom in or out of the dependency graph to see a group of objects. See the below screenshot to know the zoom feature. you can move and see the project elements.

Conclusion

I genuinely think NDepend is very powerful and very easy to use for analyzing application architecture. The NDepend team and Patrick are very active and we can expect a lot of good improvements in future versions which help to create quality software.

NDepend: New Feature “Technical Debt and Quality Gate”

What are the quality gates
Quality gates are basically acceptance criteria reviews that can be used throughout any project. Sure, managers of smaller, agile projects might say that this involves too much paperwork, but the nice thing about quality gates is that the strategy is fully customizable. It can be seen as a set of predefined quality criteria that a software development project must meet in order to proceed from one stage of its lifecycle to the next.

These are special milestone in a software project which are located before a phase that is strongly dependent on the outcome of a previous phase. They are especially useful between phases in which breaches in disciplines must be overcome.

How quality gates work:

You are not allowed to proceed the next gate until the previous gate has been completed successfully. It involves a checklist of deliverables, with some indication of the state of completion for each item. Checklist must be reviewed by the project manager (Manager) and a senior executive or stack-holders who is involved with the project. Quality gates therefore mean:

  • Formal checklists are used throughout the life of a project.
  • Formal sign-off and acceptance occurs at each gate.
  • Assessment of the quality and integrity of the product takes place.
  • Information is assured to be communicated to the correct stakeholders

Advantages of the Quality gates:
These are effective on any kind of project. There attractive because of the following advantages which includes:

  • Minimizes project failure risks through phase-by-phase checklists (or Gates)
  • Enables project managers to continuously communicate the process and build quality directly into the project
  • Reduces development cycle time—getting it done right the first time
  • Increases focus on a well-designed product

Now NDepend is equipped with this in v2017.1 and you will find default quality gates relative to technical debt and issues and issues, including Percentage of Debt, New Debt since Baseline or New Blocker / Critical / Major Issues. Quality gates relative to absolute technical debt value are disabled by default because the proper thresholds can only be defined in the context of a particular project.

Results of the applied rules are shown in the updated dashboard. This is quite new feature in NDepend for project management improvement.

image

You will find ratings and the status of passed rules.

image

HTML report has more details in a tabular format about the applied rules:

image

Then again the feature that I most like in NDepend is CQLinq which enables you to customize or add rules. CQLinq is much fast to run these rules and now much improved in case of performance.

image

There is a nice documentation is also available to know that how to Compute and Manage the Technical Debt with NDepend.

What's new in NDepend v2017.1

After my first article “Analyzing the Quality of your code with NDepend” on NDepend, I found few new interesting feature in it’s new release. Microsoft has introduced new version of the Visual Studio which my first choice for development. New Roslyn platform heading us to the Open source development using the Microsoft tools that making things easier to learn and get knowledge about the new tools. But we are going to explorer new features of the NDepend. Few of them are as below:
Support for Visual Studio 2017

  • NDepend 2017.1 supports Visual Studio 2017.
  • NDepend 2017.1. It also supports Visual Studio 2015, 2013, 2012 and 2010.

    NDepend_7_VS_Integration

.NET Core support

  • NDepend can now analyze any .NET Core assembly and its associated PDB and source files.
  • The new .NET Core Portable PDB file format is now also supported.
  • Support for inferring code to analyze from a project.json file, which about to completely come in the first quarter of this year. All .NET Core assemblies you need to analyze can be easily found through Analyze .NET assemblies in directory (recursive).

Dashboard Improvements

  • Dashboards have been improved in the NDepend UI in Visual Studio, in the generated reports section and in the Team Services web portal.
  • It now contains technical debt estimations, quality gates, rules and issues data.
  • For each data, a visual indicator shows the progression since baseline. Red and green coloured values are used to pinpoint progress or regression.
  • Clicking any value generates a query that drills down through corresponding data, which can be a list of code elements, debt estimations, quality gates, rules or issues.

    NDepend_Deshboard

Visual Studio Team Services VSTS and TFS 2017 Advanced Extension
A new Visual Studio Team Services extension is available. It consists of a build task that analyses code and code coverage yielded by the build process.
A web portal presents the results which embeds the NDepend dashboard and makes data actionable by drilling down anything with a single click.

A new Visual Studio Team Services extension is available. It consists of a build task that analyses code and code coverage yield by the build process. A web portal presents analysis results.clip_image004[4]

  • The web portal has a dashboard that presents the most relevant data including technical debt, code size, quality gates, rules and issues numbers.
  • A TFS build can be used as a baseline. All dashboard data is then diff-ed since the baseline.
  • Each data presented in the dashboard is clickable to view more information.
    clip_image006[4]
  • A detailed summary of quality gates is available.
    clip_image008[4]
  • Technical debt can be drilled down till the issue level. Clicking an issue allows it to be edited in the Rules panel.
    The datagrid is interactive: issues can be grouped, ordered and filtered by rule name.
    clip_image010
  • Rules details can be explored. Clicking a rule violation redirects the user to the VSTS Code Search extension, displaying the source code of the culprit code element.
    clip_image012
  • The VSTS extension logs trend metrics for each build, and Trend charts are shown.
    clip_image014
  • A panel shows a code metrics recap for each code element. The datagrid is interactive: elements can be grouped, ordered and filtered by name.
    clip_image016

Report Improvements

  • The new improved report dashboard now contains information on debt and issues.
    clip_image018
  • The report main section contains Quality Gates status summary.
    clip_image020
  • The report Rules Summary now shows the number of issues added and fixed per rule.
    clip_image021[4]
  • A green/red colour scale is now shown on code coverage values.
    clip_image022[4]

Code Querying Improvements

  • Thanks to the new queryable domains QualityGates, Issues, IssuesInBaseline, Rules queries can be written to match IQualityGate, IIssue, IRule objects according to any criteria (rule violated or not, quality gate status that went from pass to fail, issues added since baseline, issues severity or debt...).
    clip_image023[4]
  • New syntax to write quality gates.
  • A new button lets you run the currently edited code query against the baseline.
    clip_image024[4]
  • A code query can now return code elements of various kinds such as assemblies, namespaces, types, methods and fields.
    This new queryable domains are available including CodeElements ANTMF ; CodeElementParents ANT ; TypesAndMembers TMF ; Members MF ; CodeContainersANTM ; AttributeTargets ATMF ; where Assemblies, Namespaces, Types, Methods, Fields.
  • A query can now return values of technical debt through new types Debt, AnnualInterest, DebtRating, Severity, TrendIcon and can also return System.Version and System.TimeSpan values.
    clip_image025[4]
  • A colour scale is now shown on query result metric values making it easier to compare them at a glance.
  • You can now write very simple queries like Methods or JustMyCode.CodeElements or codebase.PercentageCoverage. This syntax simplifies writing quality gates and trend metrics queries.
  • Trend metrics used to only be defined with queries that return a scalar. A trend metric can now also be defined with a query that returns rows. In such situation the trend metric value is equals to the row count.
  • Improved query edit experience including:
    - PageUp/PageDown and dot supported on completion items list
    - smart query results column width auto-adjustment
    - no more flickering on query result row sorting.

Smart Technical Debt Estimation

NDepend v2017 is the only VS extension that can tell the developer that, for example, since this morning the code just written has introduced debt that would cost about 30 minutes should it have to be repaid later.
Knowing this, the developer can fix the code before even committing it to the source control.

  • An NDepend rule can now assign a technical debt and annual interest values to its issues.
  • The technical-debt is the estimated man-time that would take to fix the issue.
  • The annual-interest is the estimated man-time consumed per year if the issue is left unfixed. This provides an estimate of the business impact of the issue.
  • Issues of a rule now have a severity level in the blocker, critical, major, minor, info range.
    The annual-interest is a measure of an issues severity. The severity and the annual-interest represent the same concept where the annual-interest is a continuous measure while the severity is a discrete measure.
  • For example the rule below matches methods which are too complex. The technical debt is linear to the methods excessive complexity and the annual-interest is linear to the methods code coverage by tests (10 minutes per year for 100% coverage, 2 hours per year for 0% coverage).
    All default rules now have these debt/interest formulas which offer real-world estimations, out of the box. If needed, these formulas can be easily customized.
    clip_image026[4]
  • The dashboard now shows estimated Debt values and evolution since baseline.
    This dashboard is available in the NDepend UI in Visual Studio, in generated reports and in the Team Services web portal.
    clip_image027[4]
  • Many facilities are proposed from the dashboard to query/sort/filter/group... the debt estimated values and the issues set.
    These facilities include sorting debt and issues per rule or per code element, focusing on new and fixed debt since baseline and issues to fix by priority heuristics.
    Customizable Quality Gates are now available to define excessive thresholds over debt estimations that might induce build failure and prevent check-in.
    Customizable trend metrics are now available to measure debt trending. The key is to offer comprehensive sets of actionable results.
  • The NDepend project properties now has a Debt and Issues panel to customize all technical debt computation aspects.
    This includes estimated Debt and Interest values conversion from man-time to cost estimation.
    This also includes Debt Ratio and SQALE Debt Rating on a code element (as defined by the SQALE method). These are expressed in percentage of the estimated technical-debt compared to the estimated effort it would take to rewrite the code element from scratch.
    Debt settings can also be shared among different NDepend projects.
    clip_image029
  • More info on Smart Technical Debt Estimation here

Quality Gates

A Quality Gate is a check on a code quality fact that must be enforced before releasing and eventually, before committing to source control.
Quality Gates for example can forbid issues with a certain severity introduced since the baseline, enforce particular code coverage by tests ratio on new and refactored code or enforce thresholds on any Technical Debt criteria.

  • CQLinq can now be used to write quality gates. Technically a quality gate is like a trend metric. It's a code query that returns a scalar or rows (in which case the value is the row count). In practice a quality gate is used to fail a build when some thresholds are violated. A warn threshold, a fail threshold and a unit can be provided.
  • Thanks to the new CQLinq capabilities, quality gates can be use to measure and monitor any fact concerning code, but also any fact concerning technical-debt, rules and issues.
  • Quality gates can also rely on differences since baseline (diff), which means that they can monitor progression like new technical debt since baseline or % code coverage on new code written since baseline.
    clip_image030[4]
  • 11 quality gates are provided per default and LINQ queries can be written to query the quality gates status.
    clip_image031[4]
  • In previous NDepend versions, a build used to fail upon critical rules failures. Now the build fails upon any quality gate failure. The critical rule concept has been kept and the default quality gate Critical Rules Violated mimics the build fail behavior of previous NDepend versions.

Issues Management

  • A new Issues menu offers actionable options to list issues to be fixed by priority, and browse debt and issues per rule or per code element.
    clip_image032[4]
  • Quality gates, rules and issues numbers are shown from the dashboard. All these numbers are clickable to get lists of quality gates, rules or issues.
    clip_image033
  • A single click allows to list issues with a particular severity, added or fixed, since baseline.
    clip_image034
  • New menu to list issues concerning a code element.
    clip_image035
  • Hovering an issue with the mouse displays a complete description.
    clip_image036
  • Code element tooltip now shows debt and issues related data.
    clip_image037

Enhanced Baseline Experience

Do you want to measure progress since this morning, last week or since the last release?
Choose the baseline in a single click from the Dashboard and harness the updated results in just a few seconds.

  • Any stored baseline can be applied from the dashboard through a single click.
    Code base diff, rules, issues and quality gates are then recomputed in a few seconds.
  • Any newly created project now has the baseline settings set to 30 days ago per default.
    As a consequence, the stored baseline with the date closest to 30 days ago is applied.
    The first analysis result of a project is compared with itself since no other result can be used as the baseline.
  • Rules and Quality Gates are now executed against both current and baseline analysis results. Debt estimation, issues and status differences can then be queried.
    clip_image039
  • The search panel can now match all code elements added, refactored or removed since baseline.
    The results also show debt and issues information.
    This perspective is ideal to browse changes and issues introduced since baseline.
    clip_image041

Default Rules-Set Improvements

  • All default rules now include debt/interest estimation formulas that offer real-world estimations of the technical-debt, out of the box. If needed, these formulas can be easily customized.
    Typically rules related to poor coverage, poor quality and poor structure are the highest source of technical-debt.
  • The new CQLinq capabilities 52 existing rules have been improved to offer less false positives and more relevant data.
  • For example the rule Avoid namespaces mutually dependent has been improved to offer actionable results. It now lists all dependencies to remove at type and method level to reach a clean layered code structure.
    clip_image043
  • New rule Assemblies should have the same version lists application assemblies that have a different version than most other application assemblies.
  • New rule Avoid non-readonly static fields.
  • New notmycode query Discard generated Namespaces from JustMyCode matches the VB.NET generated namespace My.
  • The notmycode query Discard generated Types from JustMyCode now also matches anonymous types.

Enhanced Visual Studio Integration

  • NDepend analysis can be started after a build to automatically refresh NDepend results. New settings are provided to avoid starting the NDepend analysis when the builds purpose is to provide up-to-date compiled bits for a run session, a debug session or a unit-test session. In such a situation, it might be preferable to avoid starting the NDepend analysis to avoid both consuming CPU cycles and distracting the developer's focus.
  • Minimal interval between NDepend results being refreshed automatically after a build in VS which can now also be expressed in minutes.

NDepend.API Improvements

  • Possibility to compute an issues-set and an issues-set-diff through a single method call thanks to the new methods ComputeIssues() and ComputeIssuesDiff() declared in ExtensionMethodsProjectAnalysis.
  • Possibility to compile a code query once and resolve it against multiple code bases. This facility represents a significant optimization when multiple resolutions are needed, because query compilation is way slower than query resolving.
    Related method ExtensionMethodsQuery.CompileNoResolve() which returns a IQueryCompiledUnresolved that presents two Resolve() methods, against a ICodeBase and an ICompareContext.
  • The new method ExtensionMethodsQuery.GenerateCompletionItems() provides completion items in code query edition context.
  • The new method ExtensionMethodsQuery.CompileMany(IEnumerable<IQuery>) takes an enumerable of IQuery and returns a dictionary of IQueryCompiled indexed by IQuery.
Conclusion
NDepend is again loaded with more improvements and features from it’s last version. NDepend team introduced above valuable feature and enhancements.
Note: Information and Images are taken from NDepend documentation.