Quantcast
Channel: NsDepCop Wiki Rss Feed
Viewing all articles
Browse latest Browse all 60

Updated Wiki: How Does It Work?

$
0
0
This project has been moved to GitHub.
For the latest documentation please follow this link:
https://github.com/realvizu/NsDepCop

How does it work?

NsDepCop can run at compile-time and/or at code editing time.
  • To run at compile time, the tool is implemented as an MsBuild task so it runs regardless of whether it was invoked via Visual Studio or via MsBuild directly (eg. by a build server).
    • NsDepCop is invoked for every C# project but it performs an analysis only if it finds a config file (config.nsdepcop) next to the csproj file. Otherwise it doesn't do anything.
  • To run the tool at code editing time it is implemented as a Roslyn DiagnosticAnalyzer which is invoked by and reports to the Visual Studio IDE.
NsDepCop analyses the source code in C# projects using a parser.
  • In the case of the MSBuild integration the parser can be Roslyn or NRefactory.
  • In the case of the VisualStudio integration it is Roslyn.
  • NsDepCop scans through the source code to find every type reference.
  • Determines the namespaces of the referenced and referring types.
  • Checks whether the namespace dependencies were allowed in the config.nsdepcop file.
  • Reports disallowed dependencies.

The parts of NsDepCop

  • NsDepCop.Core.dll
    • Config file handling and the core logic of the analysis implemented with both the NRefactory API and the Roslyn API.
  • NsDepCop.MsBuildTask.dll
    • Implements a custom MSBuild task, and invokes the core analysis logic for the source files of a csproj.
  • NsDepCop.ItemTemplate.zip
    • Visual Studio item template for the NsDepCop config file.
  • NsDepCop.VisualStudioIntegration.dll
    • Implements a Roslyn DiagnosticAnalyzer and invokes the core analysis logic for the nodes that Roslyn handles to it.
  • NsDepCop.vsix
    • Wraps the DiagnosticAnalyzer and the NsDepCop.ItemTemplate into a Visual Studio extension package.
  • NsDepCop.msi
    • The setup package.
  • NsDepCop.Setup.CustomActions.dll

Integration into the C# build process

  • A custom MSBuild task can be integrated into the C# build process by adding an extra step into every csproj file or by adding it to Custom.After.Microsoft.CSharp.targets which is included by every csproj. NsDepCop does the latter.
  • Setup injects the following tags into Custom.After.Microsoft.CSharp.targets:
<Projectxmlns="http://schemas.microsoft.com/developer/msbuild/2003"><UsingTaskAssemblyFile="NsDepCop.MsBuildTask.dll"TaskName="Codartis.NsDepCop.MsBuildTask.NsDepCopTask"/><PropertyGroup><BuildDependsOn>$(BuildDependsOn);NsDepCop</BuildDependsOn></PropertyGroup><TargetName="NsDepCop"><NsDepCopTaskReferencePath="@(ReferencePath)"Compile="@(Compile)"BaseDirectory="$(MSBuildProjectDirectory)"/></Target></Project>
  • UsingTask: tells MsBuild which assembly implements the NsDepCop task.
  • PropertyGroup/DependsOn: adds NsDepCop as an extra step to the BuildDependOn property group. So NsDepCop is the last task that executes right before the Build target.
  • Target Name="NsDepCop": calls the NsDepCop custom MsBuild task and passes some parameters to it.
    • The ReferencePath item group contains all referenced assemblies.
    • The Compile item group contains all source files to be compiled.
    • BaseDirectory is the folder where the csproj file resides.
    • Parser (optional) is the name of the parser to use: NRefactory or Roslyn. Defaults to Roslyn.
    • InfoImportance (optional) specifies the info log events' message importance level: Low, Normal, High. Defaults to Normal.

Setup

The setup is created with WiX.

Prerequisite checks:
  • MSBuild 14 is required for all features.
Features:
  • MSBuild integration
    • Installs to folder: (program files 32-bit)\MSBuild\v14.0
    • Installs NsDepCop, NRefactory and Roslyn files.
    • Creates or modifies this file with custom actions: Custom.After.Microsoft.CSharp.targets (see: Integration into the C# build process)
    • Installs the NsDepCopConfig.xsd into the Visual Studio schema cache folder.
  • Visual Studio integration (VSIX)
    • Prereq: Visual Studio 2015
    • Installs a Visual Studio extension package: NsDepCop.vsix

Viewing all articles
Browse latest Browse all 60

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>