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.


.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.


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.
  • A detailed summary of quality gates is available.
  • 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.
  • 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.
  • The VSTS extension logs trend metrics for each build, and Trend charts are shown.
  • A panel shows a code metrics recap for each code element. The datagrid is interactive: elements can be grouped, ordered and filtered by name.

Report Improvements

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

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...).
  • New syntax to write quality gates.
  • A new button lets you run the currently edited code query against the baseline.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 11 quality gates are provided per default and LINQ queries can be written to query the quality gates status.
  • 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.
  • 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.
  • A single click allows to list issues with a particular severity, added or fixed, since baseline.
  • New menu to list issues concerning a code element.
  • Hovering an issue with the mouse displays a complete description.
  • Code element tooltip now shows debt and issues related data.

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.
  • 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.

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.
  • 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.
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.

Analyzing the Quality of your code with NDepend

Throughout my carrier I have worked on various projects in different environment. Few of them are completed solo and few are with small or big teams. As per my opinion and learning till now “Writing a good and clean code is an art”. This is improved with experience and learning about the “Design Patterns”.

When you are doing project as one man army then you are good to write better code and refactor it maximum as per your understanding and knowledge, but when it done with in a large project and team then a project manager or Architect will definitely worry about the quality and success of the project.

In starting days of my carrier, One day my manager asked me to learn about the Cohesion and Coupling. I was not able to understand it much at that time and tried so many time to implement it in my coding practices. After continuously taking care of such factors and knowing about the “Design Patterns” e.g. SOLID, FAÇADE etc. what I have realized that all of these things redirect the programmers to make “Quality Code”.

After this when it comes to manage a big project then you require some tools which help to find issues in a large project. It makes an architect to keep free from these below question for some instance:

  • Is the code looking good?
  • What about its complexity and test coverage?
  • Can you consider the code as maintainable with a good scalability?
  • Are there instances of copy and paste code smells?
  • How loosely and tightly coupled is the architecture? (In terms of cohesion and coupling etc.)

Doing this task manually is a time consuming process because checking and running every module will definitely consume some time. Without running the project it is possible in manually compiling and inspecting but with the tools it is much time saving process.

To check the quality of the code and analyze, I put my hands on Visual Studio inbuilt tools e.g. Unit Test Runner, Code Metrics, and Static Code Analyzes. These tools are good to work but there are few third party tools available to do some task with high precision analyzes e.g. FxCop, JustCode, ReSharper, and NDepend.

In this article, I am going to explorer the features and benefits of NDepend.

What is NDepend and its use??

NDepend is a static code analyzes for .NET. NDepend can be used in both standalone and Visual Studio integrated mode (Through Visual Studio extension). This nice tool is create by Patrick Smacchia for the developer community.

NDepend Visual Studio extension performs a range of analyzes across a solution, either during design time or retrospectively across an existing project. Current version of NDepend 6 provides 82 Code Metrics which are analyzed and reported on by the tool either in GUI or html format.

Right now I have used it in Visual Studio Integration mode. I prefer to use in integrated environment rather than doing application switch for doing same thing in different window and NDepend provide most of its functionality in Visual Studio while working with the project through a separate menu.


Setting NDepend Integration with Visual Studio:

To enable work NDepend in Visual Studio, NDepend guys provides an extension installer “NDepend.VisualStudioExtension.Installer.exe”. Check highlighted file in the below image.


Once you run this extension installer it will pop up an installation dialog which let us to integrate NDepend in our desired version of Visual Studio. Right now I am using Visual Studio 2015, so I installed for my IDE.


After completing installation, you can access to various metrics, rules, graph, reports, analyzer results and tools at one place to analyze the project for different aspect of the quality measures.

NDepend is mainly a static analyzes tool and more. It provide out of the box rule and customizability of rule through CQLinq, Visual Dependency representation, Build Integration and Change tracking. NDepend allow us to write own custom rules and you can visualize your code base and its dependencies with series of matrices and graphs as well.

It does more than providing snapshot of the code base at moment some times. It integrates in to Build process and allows us to monitor the evolution of the code and decide whether you making progress towards quality or not.

Start analyzing my first project with NDepend

After installing NDepend in Visual Studio, I found it very user friendly and quite intuitive. You can just select project from the NDepend menu to start analyzing it. Let see how its start screen looks like in first glance.


Here you can select specific menu to start working with NDepend. Now my solution is open so I am just going attach a new NDepend project to current solution. Just click on the circle in status bar of the Visual Studio and you have access to NDepend here also. See below image.


Now select “Attach new NDepend project to current VS Solution”. Now it prompt to select the assembly to analyze and you can also add another assemblies on below screen.


Just click on “Analyze a single .NET Assembly”. Now it start analyzing the assembly and after completion of process it will pop up a dialog and along this generates html report about the analyze results.


I am going to click on the View NDepend Dashboard and it redirected me to dashboard.


  And html generated report is shown as below:


In Visual Studio, there are lots of windows available through NDepend to analyze quality of the code base and even you can customize these. I am going through main features of the NDepend one by one. See below screen shot with Queries and Rules Explorer, Dependency Graph and Queries editor. 


Code Rule and Code Query over LINQ (CQLinq)

NDepend project provides build-in metrics when you create a new project to analyze an assembly. As I saw in Queries and Rules Explorer, there are more than 200 default project rules and their queries.

These rules are made up using the CQLinq. CQLinq is default scripting for NDepend to create rule queries. So in this way you can create our own queries and customize them too. CQLinq editor provides code completion and intellisense with live error description.


Dependency Matrix

Dependency Matrix shows dependency and coupling between the projects and their module. NDepend must responsive and easy navigate through the dependencies between the projects. When you click on any cell then it shows graph and information in tooltip manner. I liked this behavior because I do not need to switch between dependency graph and dependency matrix. They are shown in a synchronized way and easy to visualize and analyze the results.


Dependency Graph

It is an interactive way to represent coupling between the code base elements. Actually NDepend provide this graph for various code exploration scenarios. You can find full description about these in documentation - Exploring Existing Code Architecture in Visual Studio through Dependency Graph.

  • Dependency Graph
  • Call Graph
  • Class Inheritance Graph
  • Coupling Graph
  • Path Graph
  • All Paths Graph
  • Cycle Graph

These various type of graphs are accessible from NDepend->Graph menu items.



Code Metrics View

Code metrics view represents tree-structured data in rectangular blocks format.


Continuous Integration Reporting

These feature matter much analyzing a huge code base. Along with CQLinq, I like NDepend for this feature. NDepend integrate with TFS, Team city etc. in build process to check for the violation of CQLinq rules continuously and these are reported to the development teams to improve the code.

NDepend can analyze source code and .NET assemblies through NDepend.Console.exe. Each time it analyzes a code base, NDepend yields a report that can inform you about the status of our development. As I described in the starting of article about the html document which generated during the analyzing process is generated during build process.

This exe is located in the installation folder and the file name is “NDepend.Console.exe”. It is integrated in the building process by specifying command line arguments.


These are the few features which I have used so far but NDepend is loaded with lots features. In my opinion NDepend is light weight, powerful and intuitive application. Customization with the rules and metrics is an additional advantage using its best part CQLinq. It also integrate with Reflector and other tools which improves the productivity. I found it much better tool for maintaining quality of the application so far. Hope NDepend will continue improving this tool in future and let development process to improvise in easy way.

Free Programming Books

There was thread on Stackoverflow which contribute the list of free programming books. The Original Source for these free books as below:
 List of freely available programming books
Further I found a nice maintained list on GitHub – Free programming books and subset of the list is here:

Parallel Programming
Partial Evaluation
Professional Development
Programming Paradigms
Regular Expressions
Reverse Engineering
Software Architecture
Theoretical Computer Science
Web Performance