This project has moved. For the latest updates, please go here.
This project has been moved to GitHub.
For the latest documentation please follow this link:
https://github.com/realvizu/NsDepCop

FAQ

1. How to choose which parser is used by NsDepCop MSBuild task?
2. "Setup is unable to add NsDepCop target to the C# build workflow..."
3. "Setup is unable to remove NsDepCop target from the C# build workflow..."
4. Anonymous types raise false alarms
5. Where can I download the .NET Compiler Platform (Roslyn) End User Preview (for Visual Studio 2013)?
6. How to suppress/enable NsDepCop info messages in the MSBuild output?

1. How to choose which parser is used by NsDepCop MSBuild task?
  • Open the Custom.After.Microsoft.CSharp.targets file.
    • Find it at: C:\Program Files (x86)\MSBuild\v14.0
  • Locate the NsDepCopTask tag.
  • Add/modify the attribute named Parser.
    • Supported values are: NRefactory, Roslyn
    • Roslyn is the default if the Parser attribute is missing or have unrecognized value.
    • Eg.
<NsDepCopTask ReferencePath="@(ReferencePath)" Compile="@(Compile)" BaseDirectory="$(MSBuildProjectDirectory)" Parser="Roslyn" />

2. "Setup is unable to add NsDepCop target to the C# build workflow..."

In order to insert the NsDepCop task into the C# project build workflow, setup creates (or modifies) the "Custom.After.Microsoft.CSharp.targets" file at "(Program Files folder)\MsBuild\v4.0". It redefines the "BuildDependsOn" property group to include the NsDepCop target as the last step just before the "Build" target executes. If you already have this file and it already contains the definition of the BuildDependsOn property group then setup won't change it (so not to mess up anything).

In this case you have to insert the NsDepCop target manually. Append a semicolon and the string "NsDepCop" at the end of the text inside the "BuildDependsOn" tags. Like this:

Before:
  <PropertyGroup>
    <BuildDependsOn>
      $(BuildDependsOn);
      MyCustomTask
    </BuildDependsOn>
  </PropertyGroup>"
After:
  <PropertyGroup>
    <BuildDependsOn>
      $(BuildDependsOn);
      MyCustomTask;
      NsDepCop
    </BuildDependsOn>
  </PropertyGroup>

3. "Setup is unable to remove NsDepCop target from the C# build workflow..."

The same problem as above when uninstalling NsDepCop. The "Custom.After.Microsoft.CSharp.targets" file at "(Program Files folder)\MsBuild\v4.0" contains a definition of the BuildDependsOn property group that is different from the content that setup creates. You have to remove the NsDepCop string from the BuildDependsOn definition manually.
4. Anonymous types raise false alarms

For anonymous types the compiler generates a class with no namespace so they will belong to the 'global namespace'. If your NsDepCop config does not allow referencing the global namespace (denoted with a single dot) then it will raise a (false) alarm.

To allow the usage of anonymous types you have to add a rule that you allow referencing the global namespace:
<Allowed From="YourNamespace" To="." />

Or to be more lax:
<Allowed From="*" To="." />

5. Where can I download the .NET Compiler Platform (Roslyn) End User Preview (for Visual Studio 2013)?

Unfortunately .NET Compiler Platform (Roslyn) End User Preview (for Visual Studio 2013) is not available from Microsoft to download any more.
You can find it in the source tree: VS2013\prereq\Roslyn End User Preview.vsix
6. How to suppress/enable NsDepCop info messages in the MSBuild output?

NsDepCop error and warning messages are always displayed in the MSBuild output.
However some NsDepCop messages are only informal (eg. analysis started, finished) and these can be suppressed or enabled.

In MSBuild you can set what kind of information messages you want to see.
  • In command line: use the /verbosity switch.
  • In Visual Studio use: Tools/Options/Projects and Solutions/Build and Run/MSBuild project build output verbosity
On the other hand you can set the importance level of the NsDepCop information messages.
  • Open the Custom.After.Microsoft.CSharp.targets file.
    • Find it at: C:\Program Files (x86)\MSBuild\v14.0
  • Locate the NsDepCopTask tag.
  • Add/modify the attribute named InfoImportance.
<NsDepCopTask ReferencePath="@(ReferencePath)" Compile="@(Compile)" BaseDirectory="$(MSBuildProjectDirectory)" InfoImportance="Low" />

MsBuild verbosity and NsDepCop InfoImportance together determine which messages will show up in the output and which will be suppressed. See MSDN for the exact relation between LoggerVerbosity and MessageImportance values.

Last edited Mar 26 at 2:16 PM by vizu, version 16

Comments

No comments yet.