Custom add-in paths

May 8, 2012 at 12:29 AM

I'm looking for a way to have StyleCop load my custom rules assembly from a custom path. I've only been able to get it to load from the same directory as StyleCop.dll.

I glanced at the code and it looks like there is a notion of add-in paths in StyleCopCore.Initialize, but I can't see how that parameter is filled in. Maybe this is a work in progress?

I would like to specify the custom add-in paths via a Settings.StyleCop file so that it is used no matter how StyleCop is invoked (via VS (right-click project / StyleCop Settings) or when the rules are run via msbuild and StyleCop.Targets or with real-time checking while I'm editing a file).

Thanks!

 

Coordinator
May 10, 2012 at 7:15 PM

If you're running StyleCop via the MSBuild task you need to set: AdditionalAddinPaths. You can see it in the StyleCop.targets file

<StyleCopTask
      ProjectFullPath="$(MSBuildProjectDirectory)"
      SourceFiles="@(StyleCopFiles)"
      AdditionalAddinPaths="@(StyleCopAdditionalAddinPaths)"
      ForceFullAnalysis="$(StyleCopForceFullAnalysis)"
      DefineConstants="$(DefineConstants)"
      TreatErrorsAsWarnings="$(StyleCopTreatErrorsAsWarnings)"
      CacheResults="$(StyleCopCacheResults)"
      OverrideSettingsFile="$(StyleCopOverrideSettingsFile)"
      OutputFile="$(StyleCopOutputFile)"
      MaxViolationCount="$(StyleCopMaxViolationCount)"
            />

Coordinator
May 10, 2012 at 7:17 PM

There isn't a way of making it happen from the IDE though as it calls:

this.Core.Initialize(null, true);
                
from the IDE passing in null as the additional addin paths.

Jan 13, 2013 at 8:21 PM
Edited Jan 13, 2013 at 8:22 PM

I've tried this but for the life of me I can't get it to work. I've even tried hardcoding the path to the DLL in StyleCop.Targets and it still doesn't work. E.g.

<StyleCopTask
      ProjectFullPath="$(MSBuildProjectDirectory)"
      SourceFiles="@(StyleCopFiles)"
      AdditionalAddinPaths="E:\Code\Personal\domaindrivendesign\lib\CustomRules.dll"
      ForceFullAnalysis="$(StyleCopForceFullAnalysis)"
      DefineConstants="$(DefineConstants)"
      TreatErrorsAsWarnings="$(StyleCopTreatErrorsAsWarnings)"
      CacheResults="$(StyleCopCacheResults)"
      OverrideSettingsFile="$(StyleCopOverrideSettingsFile)"
      OutputFile="$(StyleCopOutputFile)"
      MaxViolationCount="$(StyleCopMaxViolationCount)"
            />
I've confirmed that my rules are indeed run when I drop the DLL into the StyleCop folder.

May 12, 2013 at 5:14 PM
adamralph try path to directory where your dll is located instead of path to dll.
May 12, 2013 at 5:17 PM
Ah, that might be it. I can't even remember why I was trying to do this now, but I'll bear it in mind, thanks.
Feb 20, 2014 at 10:00 PM
Where is it you place the MSBuild StyleCopTask? Is that in your project? Then you can add paths, such as to a User Local AppData type thing? Thank ye...