Table of Contents

Class ExtensionMethodsProjectAnalysis

Namespace
NDepend.Analysis
Assembly
NDepend.API.dll

Provides a set of extension methods to run analysis (only available with a Build Machine license) and to collect existing analysis results references.

public static class ExtensionMethodsProjectAnalysis
Inheritance
ExtensionMethodsProjectAnalysis
Inherited Members

Methods (32)

AnalyzeAssemblies(ICollection<IAbsoluteFilePath>)

Analyze a set of assemblies, in-process and synchronously, and return a IAnalysisResult object. (Only available with a Build Machine license).

public static IAnalysisResult AnalyzeAssemblies(this ICollection<IAbsoluteFilePath> applicationAssembliesPath)

Parameters

applicationAssembliesPath ICollection<IAbsoluteFilePath>

A collection of IAbsoluteFilePath object that contains assemblies file paths.

Returns

IAnalysisResult

The analysis result.

Remarks

Calling this method will typically takes a few seconds, the time the analysis is performed.
Internally, this methods creates a temporary project with the method CreateTemporaryProject(ICollection<IAbsoluteFilePath>, TemporaryProjectMode) and then call RunAnalysis(IProject, string) on this temporary project. It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

Exception

Cannot run analysis without a Build Machine license.

ProjectException

Problem with creating a temporary project.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

AnalyzeAssemblies(ICollection<string>)

Analyze a set of assemblies, in-process and synchronously, and return a IAnalysisResult object. (Only available with a Build Machine license).

public static IAnalysisResult AnalyzeAssemblies(this ICollection<string> applicationAssembliesPath)

Parameters

applicationAssembliesPath ICollection<string>

A collection of string that contains assemblies file paths.

Returns

IAnalysisResult

The analysis result.

Remarks

Calling this method will typically takes a few seconds, the time the analysis is performed.
Internally, this methods creates a temporary project with the method CreateTemporaryProject(ICollection<IAbsoluteFilePath>, TemporaryProjectMode) and then call RunAnalysis(IProject, string) on this temporary project. It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

ProjectException

Problem with creating a temporary project.

Exception

Cannot run analysis without a Build Machine license.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

ArgumentNullException

One of the string in applicationAssembliesPath is null.

ArgumentException

One of the string in applicationAssembliesPath is not a valid absolute file path.

FileNotFoundException

One absolute file path in applicationAssembliesPath doesn't exist.

BuildAnalysisResultRefFor(IProject, IAbsoluteFilePath)

Create an IAnalysisResultRef object from a project, an analysis result file (.ndar extension) and a date.

public static IAnalysisResultRef BuildAnalysisResultRefFor(this IProject project, IAbsoluteFilePath analysisResultFilePath)

Parameters

project IProject

The project.

analysisResultFilePath IAbsoluteFilePath

The analysis result file path (.ndar extension).

Returns

IAnalysisResultRef

The analysis result reference.

Remarks

The analysis result is not loaded, only the reference to the analysis result is returned.
The IAnalysisResultRef.Date is inferred from the directy path if the analysis result parent directory path. NDepend stores historic analysis result in a folder hierarchy named after YYYY_MM and then sub folder DD_HH_MM_SS.
If the analysis result file is not stored in such folder, IAnalysisResultRef.Date is the last write date of the analysis result file.

Exceptions

FileNotFoundException

This exception is thrown if the analysis result file analysisResultFilePath doesn't exist.

CanAllPathsReferencedBeResolvedAsAbsolute(IProject)

This method returns a list of string, that each describes in plain-english, the failure to resolve as absolute a path referenced by project. The list returned is empty if all paths can be resolved as absolute.

public static IReadOnlyList<string> CanAllPathsReferencedBeResolvedAsAbsolute(this IProject project)

Parameters

project IProject

The project on which to try to resolve paths referenced as absolute.

Returns

IReadOnlyList<string>

ComputeIssues(IAnalysisResult)

This method compiles and runs all rules against analysisResult.CodeBase and returns all issues in an IIssuesSet object.

public static IIssuesSet ComputeIssues(this IAnalysisResult analysisResult)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

Returns

IIssuesSet

Remarks

This method calls ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>) with one day for cqlinqQueryExecTimeOut parameter, and with IssueReferenceRecord.No value for issueReferenceRecord parameter.

ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules on analysisResult.CodeBase and returns all issues in an IIssuesSet object.

public static IIssuesSet ComputeIssues(this IAnalysisResult analysisResult, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCode, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

justMyCode ICodeBaseView

The just-my-codeICodeBaseView object computed, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english logs that represent all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSet object.

Returns

IIssuesSet

Remarks

The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes the just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns it through justMyCode .

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

ComputeIssuesAndTrendMetrics(IAnalysisResult, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules and trend metrics on analysisResult.CodeBase and returns all issues in an IIssuesSet object and returns also all trendMetricsValues.

public static IIssuesSet ComputeIssuesAndTrendMetrics(this IAnalysisResult analysisResult, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCode, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

trendMetricsValues IReadOnlyList<MetricValue>

The trend metrics values extracted from the project analysisResult.AnalysisResultRef.Project.

justMyCode ICodeBaseView

The just-my-codeICodeBaseView object computed, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english logs that represent all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSet object.

Returns

IIssuesSet

Remarks

This method is optimized and takes account of the returned IIssuesSet object to compute trend metrics. Hence this method is almost twice faster than calling first ComputeIssues(IAnalysisResult) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes the just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns it through justMyCode .

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

ComputeIssuesDiff(IAnalysisResult, ICompareContext)

This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.

public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

compareContext ICompareContext

Issues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.

Returns

IIssuesSetDiff

Remarks

ComputeIssuesDiff(IAnalysisResult, ICompareContext, IRuleIssues[], IRuleIssues[], TimeSpan, IssueReferenceRecord, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.

public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] newIssuesImported, IRuleIssues[] oldIssuesImported, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

compareContext ICompareContext

Issues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.

newIssuesImported IRuleIssues[]

Issues imported for the newer snapshot.

oldIssuesImported IRuleIssues[]

Issues imported for the older snapshot.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

justMyCodeNew ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.NewerCodeBase, against which rules have been executed.

justMyCodeOld ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.OlderCodeBase, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.

Returns

IIssuesSetDiff

Remarks

The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase, except rule that relies on diff, like the rule API breaking change for example. Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.

If a rule has compilation or execution error on one code base snapshot but not on the other one, a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.

ComputeIssuesDiff(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object.

public static IIssuesSetDiff ComputeIssuesDiff(this IAnalysisResult analysisResult, ICompareContext compareContext, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

compareContext ICompareContext

Issues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

justMyCodeNew ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.NewerCodeBase, against which rules have been executed.

justMyCodeOld ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.OlderCodeBase, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.

Returns

IIssuesSetDiff

Remarks

The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase, except rule that relies on diff, like the rule API breaking change for example. Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.

If a rule has compilation or execution error on one code base snapshot but not on the other one, a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.

ComputeIssuesDiffAndTrendMetrics(IAnalysisResult, ICompareContext, IRuleIssues[], IRuleIssues[], TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules and trend metrics against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object and returns also all trendMetricsValues.

public static IIssuesSetDiff ComputeIssuesDiffAndTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] newIssuesImported, IRuleIssues[] oldIssuesImported, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

compareContext ICompareContext

Issues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.

newIssuesImported IRuleIssues[]

Issues imported for the newer build.

oldIssuesImported IRuleIssues[]

Issues imported for the older build.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

trendMetricsValues IReadOnlyList<MetricValue>

The trend metrics values extracted from the project analysisResult.AnalysisResultRef.Project.

justMyCodeNew ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.NewerCodeBase, against which rules have been executed.

justMyCodeOld ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.OlderCodeBase, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.

Returns

IIssuesSetDiff

Remarks

This method is optimized and takes account of the returned IIssuesSetDiff object to compute trend metrics. Hence this method is almost twice faster than calling first ComputeIssuesDiff(IAnalysisResult, ICompareContext) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase, except rule that relies on diff, like the rule API breaking change for example. Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.

If a rule has compilation or execution error on one code base snapshot but not on the other one, a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.

ComputeIssuesDiffAndTrendMetrics(IAnalysisResult, ICompareContext, TimeSpan, IssueReferenceRecord, out IReadOnlyList<MetricValue>, out ICodeBaseView, out ICodeBaseView, out IEnumerable<IIssueComputationLog>)

This method compiles and runs all rules and trend metrics against both code base snapshots of compareContext (NewerCodeBase and OlderCodeBase) and returns all baseline and newer issues compared in an IIssuesSetDiff object and returns also all trendMetricsValues.

public static IIssuesSetDiff ComputeIssuesDiffAndTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, TimeSpan cqlinqQueryExecTimeOut, IssueReferenceRecord issueReferenceRecord, out IReadOnlyList<MetricValue> trendMetricsValues, out ICodeBaseView justMyCodeNew, out ICodeBaseView justMyCodeOld, out IEnumerable<IIssueComputationLog> logs)

Parameters

analysisResult IAnalysisResult

The analysis result on which to compute the issues.

compareContext ICompareContext

Issues are computed for both this ICompareContext object NewerCodeBase and OlderCodeBase, and are the compared in the return IIssuesSetDiff object.

cqlinqQueryExecTimeOut TimeSpan

The code query execution time-out duration.

issueReferenceRecord IssueReferenceRecord

A value that indicates if each issue in the returned IIssuesSet object references the corresponding query execution RecordBase object.

trendMetricsValues IReadOnlyList<MetricValue>

The trend metrics values extracted from the project analysisResult.AnalysisResultRef.Project.

justMyCodeNew ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.NewerCodeBase, against which rules have been executed.

justMyCodeOld ICodeBaseView

The just-my-codeICodeBaseView object computed for compareContext.OlderCodeBase, against which rules have been executed.

logs IEnumerable<IIssueComputationLog>

A sequence of plain-english log that represents all problems found while compiling and executing rules, and that can explain some unexpected issues state in the returned IIssuesSetDiff object.

Returns

IIssuesSetDiff

Remarks

This method is optimized and takes account of the returned IIssuesSetDiff object to compute trend metrics. Hence this method is almost twice faster than calling first ComputeIssuesDiff(IAnalysisResult, ICompareContext) and then LogTrendMetrics(IAnalysisResult, DateTime).
If you wish to log the obtained trendMetricsValues first call TryComputeLogLabel(IProject, ICodeBase, out string) and then call LogTrendMetrics(IAnalysisResult, DateTime).
The rules are the active rules found in the project analysisResult.AnalysisResultRef.Project, the active rules in active rule file(s) referenced by this project, and the active rules found in analysisResult.RulesExtractedFromCode.

The issues debt is computed and formatted against this project IProjectDebtSettings.

Before running the rules, this method also computes both just-my-codeICodeBaseView from active code queries prefixed with notmycode, found in the same locations than the rules, and returns them through justMyCodeOld and justMyCodeNew.

Returned sequence of logs contains plain-english logs that represent all problems found while compiling and executing rules. This includes rules compilation / execution errors, rules that rely on code coverage not available, rules that relies on diff not available.

Rules are executed twice against compareContextNewerCodeBase and OlderCodeBase, except rule that relies on diff, like the rule API breaking change for example. Such rule is only executed once and its issues are only present in the NewerIssuesSet of the returned IIssuesSetDiff object.

If a rule has compilation or execution error on one code base snapshot but not on the other one, a log is emitted and issues obtained from execution against the other snapshot are not taken account in the returned IIssuesSetDiff object.

GetAvailableAnalysisResultsRefs(IProject)

Gets a collection of all analysis results available for this project ordered by IAnalysisResultRef.Date descending.

public static IReadOnlyList<IAnalysisResultRef> GetAvailableAnalysisResultsRefs(this IProject project)

Parameters

project IProject

This NDepend project.

Returns

IReadOnlyList<IAnalysisResultRef>

Remarks

If project.HistoricAnalysisResult doesn't save historic analysis results, then the returned list will contain the most recent analysis result available for this project, or nothing if no analysis result is available for this project.
On a NDepend project with many analysis results available for years, it is performant wise to prefer calling GetAvailableAnalysisResultsRefsGroupedPerMonth(IProject) instead of this method, because analysis results references are then lazy-resolved, per month.

GetAvailableAnalysisResultsRefsGroupedPerMonth(IProject)

Gets a collection of all analysis results available for this project, grouped per months.

public static IReadOnlyList<IAnalysisResultsRefsForAMonth> GetAvailableAnalysisResultsRefsGroupedPerMonth(this IProject project)

Parameters

project IProject

This NDepend project.

Returns

IReadOnlyList<IAnalysisResultsRefsForAMonth>

Remarks

If project.HistoricAnalysisResult doesn't save historic analysis results, then the returned list will contain the most recent analysis result available for this project, or nothing if no analysis result is available for this project.
On a NDepend project with many analysis results available for years, it is performant wise to call this method than calling GetAvailableAnalysisResultsRefs(IProject), because analysis results references are then lazy-resolved, per month.

LoadAnalysisResultFromFile(IProject, IAbsoluteFilePath)

Loads the analysis result of a project from an analysis result file (.ndar extension).

public static IAnalysisResult LoadAnalysisResultFromFile(this IProject project, IAbsoluteFilePath analysisResultFilePath)

Parameters

project IProject

The project.

analysisResultFilePath IAbsoluteFilePath

The analysis result file path.

Returns

IAnalysisResult

The analysis result loaded.

Exceptions

AnalysisException

If the analysis load fails, an AnalysisException with an informative message is thrown.

FileNotFoundException

This exception is thrown if the analysis result file analysisResultFilePath doesn't exist.

LoadCodeBaseFromAnalysisResultFile(IAbsoluteFilePath)

Loads a code base snapshot from an analysis result file (.ndar extension).

public static ICodeBase LoadCodeBaseFromAnalysisResultFile(this IAbsoluteFilePath analysisResultFilePath)

Parameters

analysisResultFilePath IAbsoluteFilePath

The analysis result file path (.ndar extension).

Returns

ICodeBase

The code base snapshot.

Exceptions

AnalysisException

If the analysis load fails, an AnalysisException with an informative message is thrown.

FileNotFoundException

This exception is thrown if the analysis result file analysisResultFilePath doesn't exist.

LogTrendMetrics(IAnalysisResult, ICompareContext, IRuleIssues[], DateTime)

Force log trend metrics values for this analysisResult, with the possibility to execute code rules and trend metrics that require to be run in diff mode.

public static void LogTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, IRuleIssues[] baselineIssuesImported, DateTime logDateTime)

Parameters

analysisResult IAnalysisResult

This analysisResult on which trend metrics values are computed.

compareContext ICompareContext

The ICompareContext object used to execute code rules and trend metrics that require to be run in diff mode.

baselineIssuesImported IRuleIssues[]

Issues imported for the baseline snapshot.

logDateTime DateTime

The time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.

Remarks

Trend metrics are extracted from code queries found in IAnalysisResult.AnalysisResultRef.Project.CodeQueries and IAnalysisResult.RulesExtractedFromCode.
Rules are extracted from the same code queries sets, for computation of code metrics: # Rules, # Rules Violated, # Rules Violations.
Trend metrics values are logged into the trend metrics store of the project IAnalysisResult.AnalysisResultRef.Project.

Exceptions

TrendStoreException

An error occurred while persisting in the trend store.

LogTrendMetrics(IAnalysisResult, DateTime)

Force log trend metrics values for this analysisResult.

public static void LogTrendMetrics(this IAnalysisResult analysisResult, DateTime logDateTime)

Parameters

analysisResult IAnalysisResult

This analysisResult on which trend metrics values are computed.

logDateTime DateTime

The time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.

Remarks

Trend metrics are extracted from code queries found in IAnalysisResult.AnalysisResultRef.Project.CodeQueries and IAnalysisResult.RulesExtractedFromCode.
Rules are extracted from the same code queries sets, for computation of code metrics: # Rules, # Rules Violated, # Rules Violations.
Trend metrics values are logged into the trend metrics store of the project IAnalysisResult.AnalysisResultRef.Project.

Exceptions

TrendStoreException

An error occurred while persisting in the trend store.

LogTrendMetrics(IProject, IReadOnlyList<MetricValue>, string, DateTime)

Force log trend metrics trendMetricsValues already computed, for this project.

public static void LogTrendMetrics(this IProject project, IReadOnlyList<MetricValue> trendMetricsValues, string label, DateTime logDateTime)

Parameters

project IProject

This project for which trend metrics values are computed.

trendMetricsValues IReadOnlyList<MetricValue>

Trend metric values already computed.

label string

The log label string. If null or empty no label will be stored. Typically this label is computed through TryComputeLogLabel(IProject, ICodeBase, out string)

logDateTime DateTime

The time at which trend metrics values are persisted, typically DateTime.Now or IAnalysisResult.AnalysisResultRef.Date.

Remarks

Exceptions

TrendStoreException

An error occurred while persisting in the trend store.

PointsToSameAnalysisResultAs(IAnalysisResultRef, IAnalysisResultRef)

Returns true if both analysis result references point to the same analysis result.

public static bool PointsToSameAnalysisResultAs(this IAnalysisResultRef ref1, IAnalysisResultRef ref2)

Parameters

ref1 IAnalysisResultRef

This analysis result reference

ref2 IAnalysisResultRef

The other analysis result reference

Returns

bool

RunAnalysis(IProject, Action<IAnalysisLog>, Action<IProgressLog>, string)

Runs a full analysis on this project, in-process and synchronously. (Only available with a Build Machine license).

public static IAnalysisResult RunAnalysis(this IProject project, Action<IAnalysisLog> analysisLogHandler, Action<IProgressLog> progressLogHandler, string analysisResultId = "")

Parameters

project IProject

This NDepend project to analyze.

analysisLogHandler Action<IAnalysisLog>

A procedure delegate object invoked each time the current analysis run emits a new IAnalysisLog object.

progressLogHandler Action<IProgressLog>

A procedure delegate object invoked each time the current analysis run emits a new IProgressLog object.

analysisResultId string

(Optional) An id to identify the analysis result build by this call.

Returns

IAnalysisResult

The analysis result.

Remarks

Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

Exception

Cannot run analysis without a Build Machine license.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

XmlException

The project file might be corrupted.

ArgumentException

The string for analysisResultId is invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |

RunAnalysis(IProject, string)

Runs a full analysis on this project, in-process and synchronously. (Only available with a Build Machine license).

public static IAnalysisResult RunAnalysis(this IProject project, string analysisResultId = "")

Parameters

project IProject

This NDepend project to analyze.

analysisResultId string

(Optional) An id to identify the analysis result build by this call.

Returns

IAnalysisResult

The analysis result.

Remarks

Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

Exception

Cannot run analysis without a Build Machine license.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

ArgumentException

The string for analysisResultId is invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |

RunAnalysisAndBuildReport(IProject, Action<IAnalysisLog>, Action<IProgressLog>, string)

Runs a full analysis on this project, in-process and synchronously, and then generate a HTML report. (Only available with a Build Machine license).

public static IAnalysisResult RunAnalysisAndBuildReport(this IProject project, Action<IAnalysisLog> analysisLogHandler, Action<IProgressLog> progressLogHandler, string analysisResultId = "")

Parameters

project IProject

This NDepend project to analyze.

analysisLogHandler Action<IAnalysisLog>

A procedure delegate object invoked each time the current analysis run emits a new IAnalysisLog object.

progressLogHandler Action<IProgressLog>

A procedure delegate object invoked each time the current analysis run emits a new IProgressLog object.

analysisResultId string

(Optional) An id to identify the analysis result build by this call.

Returns

IAnalysisResult

The analysis result.

Remarks

The report generated is available in project.Properties.OutputDir, named "NDependReport.html".
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

Exception

Cannot run analysis without a Build Machine license.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

ArgumentException

The string for analysisResultId is invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |

RunAnalysisAndBuildReport(IProject, string)

Runs a full analysis on this project, in-process and synchronously, and then generate a HTML report. (Only available with a Build Machine license).

public static IAnalysisResult RunAnalysisAndBuildReport(this IProject project, string analysisResultId = "")

Parameters

project IProject

This NDepend project to analyze.

analysisResultId string

(Optional) An id to identify the analysis result build by this call.

Returns

IAnalysisResult

The analysis result.

Remarks

The report generated is available in project.Properties.OutputDir, named "NDependReport.html".
Calling this method will typically takes a few seconds, the time the analysis is performed.
The analysis result is persisted in the project.Properties.OutputDir directory.
It is possible to run several analysis simultaneously on several threads in the same AppDomain.

Exceptions

Exception

Cannot run analysis without a Build Machine license.

AnalysisException

The analysis execution failed. The InnerException contains additional information concerning the failure.

ArgumentException

The string for analysisResultId is invalid. It must be trimmed, a length of maximum 64 characters, excluding characters that cannot fit in a file name \ / : * ? " > < |

TryComputeLogLabel(IProject, ICodeBase, out string)

Try compute the log label from project and codeBase.

public static bool TryComputeLogLabel(this IProject project, ICodeBase codeBase, out string label)

Parameters

project IProject

The project that contains trend metrics log settings.

codeBase ICodeBase

The code base thta contains application assemblies from which log versionning is inferred.

label string

The log label returned.

Returns

bool

Remarks

Typically this method is called to compute the parameter label in this overload LogTrendMetrics(IAnalysisResult, DateTime).

TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string)

Exports these issues in JSON or SARIF, without quality gates. This is the content written by NDepend.Console.exe /IssueCheck with /OutJson or /OutSarif, and by the Export Issues to SARIF File menu of a query result that matches issues.

public static bool TryExportIssues(this IEnumerable<IIssue> issues, IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IssuesExportFormat format, out string content, out string failureReason, string issuesQueryName = null)

Parameters

issues IEnumerable<IIssue>

The issues to export. They must belong to issuesSet. Duplicates are exported once.

analysisResult IAnalysisResult

The analysis result on which issuesSet has been computed. Its project name, project file path and analysis date are exported.

issuesSet IIssuesSet

The issues-set computed on analysisResult.

issuesSetDiff IIssuesSetDiff

Can be null. Else the issues-set-diff whose NewerIssuesSet is issuesSet: it tells which issues are new.

format IssuesExportFormat

The export format, JSON or SARIF.

content string

The JSON or SARIF document if the method returns true, else null.

failureReason string

A description of the failure if the method returns false, else null.

issuesQueryName string

Optional: the name of the rule or of the query that matched issues, exported as issuesQuery.

Returns

bool

true if the export succeeded.

Remarks

To export the issues of a rule or of a query from its rule id, its rule name or its query name, or the issues matched by a code query compiled, first get them and the name to export as issuesQueryName with TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, string, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?) or TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IQueryCompiledSuccess, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?).

The JSON format is described by the schema https://www.ndepend.com/schemas/issues-export/1.0.json, the quality gates properties are null. The SARIF format is SARIF 2.1.0.

The message of each issue contains the issue explanation only if the issues have been computed with IssueReferenceRecord.Yes.

TryExportQualityGatesAndIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string)

Exports the quality gates status and all the issues of issuesSet in JSON or SARIF. This is the content written by NDepend.Console.exe /QualityGateCheck with /OutJson or /OutSarif.

public static bool TryExportQualityGatesAndIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IssuesExportFormat format, out string content, out string failureReason)

Parameters

analysisResult IAnalysisResult

The analysis result on which issuesSet has been computed. Its project name, project file path and analysis date are exported.

issuesSet IIssuesSet

The issues-set computed on analysisResult.

issuesSetDiff IIssuesSetDiff

Can be null. Else the issues-set-diff whose NewerIssuesSet is issuesSet: it tells which issues are new, and the count of issues fixed since the baseline.

format IssuesExportFormat

The export format, JSON or SARIF.

content string

The JSON or SARIF document if the method returns true, else null.

failureReason string

A description of the failure if the method returns false, else null.

Returns

bool

true if the export succeeded.

Remarks

The JSON format is described by the schema https://www.ndepend.com/schemas/issues-export/1.0.json. The SARIF format is SARIF 2.1.0, the quality gates are in the run property bag.

The message of each issue contains the issue explanation only if the issues have been computed with IssueReferenceRecord.Yes, see ComputeIssues(IAnalysisResult, TimeSpan, IssueReferenceRecord, out ICodeBaseView, out IEnumerable<IIssueComputationLog>). Else the message contains the code element and the values of the rule columns.

TryGetAnalysisResultRefToCompareWith(IProjectBaseline, out IAnalysisResultRef)

Try gets an analysis reference corresponding to this project baseline to compare with.

public static TryGetAnalysisResultRefToCompareWithResult TryGetAnalysisResultRefToCompareWith(this IProjectBaseline projectBaseline, out IAnalysisResultRef analysisResultRef)

Parameters

projectBaseline IProjectBaseline

This NDepend project baseline, obtained from IProject.BaselineDuringAnalysis or IProject.BaselineInUI.

analysisResultRef IAnalysisResultRef

If the method returns TryGetAnalysisResultRefToCompareWithResult.DoCompareWith, analysisResultRef is not null and references the analysis result used for baseline.

Returns

TryGetAnalysisResultRefToCompareWithResult

TryGetAnalysisResultRefToCompareWithResult.DoCompareWith if an an analysis result reference representing the baseline to compare with can be found, else returns another value of the enumeration TryGetAnalysisResultRefToCompareWithResult.

TryGetAnalysisResultRefToCompareWith(IProjectBaseline, out IAnalysisResultRef, out string)

Try gets an analysis reference corresponding to this project baseline to compare with.

public static TryGetAnalysisResultRefToCompareWithResult TryGetAnalysisResultRefToCompareWith(this IProjectBaseline projectBaseline, out IAnalysisResultRef analysisResultRef, out string failureReason)

Parameters

projectBaseline IProjectBaseline

This NDepend project baseline, obtained from IProject.BaselineDuringAnalysis or IProject.BaselineInUI.

analysisResultRef IAnalysisResultRef

If the method returns TryGetAnalysisResultRefToCompareWithResult.DoCompareWith, analysisResultRef is not null and references the analysis result used for baseline.

failureReason string

If the method returns TryGetAnalysisResultRefToCompareWithResult.ErrorGettingTheAnalysisResultRef, failureReason is not null not empty, and explains in plain-english why the project baseline cannot be retrieved.

Returns

TryGetAnalysisResultRefToCompareWithResult

TryGetAnalysisResultRefToCompareWithResult.DoCompareWith if an an analysis result reference representing the baseline to compare with can be found, else returns another value of the enumeration TryGetAnalysisResultRefToCompareWithResult.

TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, IQueryCompiledSuccess, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?)

Gets the issues matched by issuesQuery.

public static bool TryGetIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, IQueryCompiledSuccess issuesQuery, out IEnumerable<IIssue> issues, out string issuesQueryName, out string failureReason, ICodeBaseView justMyCode = null, TimeSpan? cqlinqQueryExecTimeOut = null)

Parameters

analysisResult IAnalysisResult

The analysis result on which issuesSet has been computed.

issuesSet IIssuesSet

The issues-set computed on analysisResult.

issuesSetDiff IIssuesSetDiff

Can be null. Else the issues-set-diff whose NewerIssuesSet is issuesSet. Needed by queries that rely on the diff.

issuesQuery IQueryCompiledSuccess

A code query compiled that matches issues.

issues IEnumerable<IIssue>

The issues matched if the method returns true, else null.

issuesQueryName string

The name of the query if the method returns true and the query has a name, else null.

failureReason string

A description of the failure if the method returns false, else null.

justMyCode ICodeBaseView

Optional: the just-my-code code base view used to execute the query, as returned by ComputeIssues().

cqlinqQueryExecTimeOut TimeSpan?

Optional: the query execution time-out, one day if null.

Returns

bool

true if the query has been executed and matches issues.

Remarks

A query that relies on the diff, like from i in Issues where i.WasAdded() select i, must be compiled against issuesSetDiff.CompareContext, see ExtensionMethodsQuery.Compile(string, ICompareContext).
The method fails if the query doesn't match issues, or matches fixed issues or suppressed issues.

To export the issues matched, call TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string) on them, with issuesQueryName.

TryGetIssues(IAnalysisResult, IIssuesSet, IIssuesSetDiff, string, out IEnumerable<IIssue>, out string, out string, ICodeBaseView, TimeSpan?)

Gets the issues of a rule or of a query, from its rule id, its rule name or its query name. This is how NDepend.Console.exe /IssueCheck "rule or query" finds the issues it exports.

public static bool TryGetIssues(this IAnalysisResult analysisResult, IIssuesSet issuesSet, IIssuesSetDiff issuesSetDiff, string ruleIdOrQueryName, out IEnumerable<IIssue> issues, out string issuesQueryName, out string failureReason, ICodeBaseView justMyCode = null, TimeSpan? cqlinqQueryExecTimeOut = null)

Parameters

analysisResult IAnalysisResult

The analysis result on which issuesSet has been computed.

issuesSet IIssuesSet

The issues-set computed on analysisResult.

issuesSetDiff IIssuesSetDiff

Can be null. Else the issues-set-diff whose NewerIssuesSet is issuesSet. Needed by queries that rely on the diff.

ruleIdOrQueryName string

A rule id, a rule name or the name of a query that matches issues.

issues IEnumerable<IIssue>

The issues found if the method returns true, else null.

issuesQueryName string

The name of the rule or of the query found if the method returns true, else null.

failureReason string

A description of the failure if the method returns false, else null.

justMyCode ICodeBaseView

Optional: the just-my-code code base view used to execute a query, as returned by ComputeIssues().

cqlinqQueryExecTimeOut TimeSpan?

Optional: the query execution time-out, one day if null.

Returns

bool

true if the rule or the query has been found.

Remarks

ruleIdOrQueryName is searched in this order, ignoring case:
1) the active rule with this id, like ND1000, or like CA1822 for an imported Roslyn rule,
2) the active rule with this name, like Avoid types too big,
3) the query with this name that matches issues, like New issues since baseline, in the project, in the rule files referenced by the project, and in analysisResult.RulesExtractedFromCode.
The method fails if the name is unknown, if several rules or queries have this name, if the rule is not active, or if the query doesn't match issues, or matches fixed issues or suppressed issues.

To export the issues found, call TryExportIssues(IEnumerable<IIssue>, IAnalysisResult, IIssuesSet, IIssuesSetDiff, IssuesExportFormat, out string, out string, string) on them, with issuesQueryName.

TryGetMostRecentAnalysisResultRef(IProject, out IAnalysisResultRef)

Gets a reference to the most recent analysis result available for this project.

public static bool TryGetMostRecentAnalysisResultRef(this IProject project, out IAnalysisResultRef mostRecentAnalysisResultRef)

Parameters

project IProject

This NDepend project.

mostRecentAnalysisResultRef IAnalysisResultRef

The reference to the most recent analysis result or null if the method call returned false.

Returns

bool

A value indicating if a most recent analysis result referece has been found for this project.