Compatibility Issues

Natively Supported Version

As you may already know, StyleCop is released with strong-named core assemblies.
That is why only one StyleCop version can be natively supported at one time.

Currently natively supported StyleCop version is 4.7.49.0.
It means if you are using StyleCop 4.7.49.0, StyleCop+ will work as is, without any additional efforts.

Of course, I am always trying to keep StyleCop+ up to date.
However, it is possible to make StyleCop+ with other StyleCop versions using assembly binding.
But you should understand that it will only work as long as StyleCop API is not changed.

Understanding Assembly Binding

Assembly bindings are special instructions in .NET configuration files which say "Hey, use this version of this assembly instead of that version".
There are two ways where to define them.
  • 1. You could define assembly bindings in global .NET configuration file and it will affect the behaviour of all .NET applications on this machine.
As a result, bindings will work for all cases described below, e.g. using StyleCop from Visual Studio, running it as MSBuild task, or just working with Settings Editor.
But you should pay attention that each .NET version has its own configuration file.
For example, Visual Studio 2010 will use one from .NET 4.0, while Settings Editor will use the other from .NET 3.5.
So you could have to update them both.
  • 2. You could setup assembly binding for the specific application that uses StyleCop.
To do this, you must locate its configuration file (or create it if it's absent) and make corresponding changes.

How to Update Configuration File

The following table shows most typical examples of where configuration file is located:

Use Case Configuration File
MachineConfigIcon.png Global .NET 2.0 / 3.0 / 3.5 configuration C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\Machine.config
- Will setup assembly bindings for all .NET 2.0 / 3.0 / 3.5 applications
MachineConfigIcon.png Global .NET 4.0 configuration C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\Machine.config
- Will setup assembly bindings for all .NET 4.0 applications
Vs2008Icon.png Visual Studio 2008 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.config
- Running StyleCop from Visual Studio 2008
Vs2010Icon.png Visual Studio 2010 C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config
- Running StyleCop from Visual Studio 2010
MsBuildIcon.png MSBuild C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe.config
- Running StyleCop from MSBuild task * Please pay attention which MSBuild version you want to use
SettingsEditorIcon.png Standalone Settings Editor C:\Program Files\StyleCop 4.5\StyleCopSettingsEditor.exe.config
- Double-click on Settings.StyleCop file * You might need to create this file manually


In order to setup assembly bindings, you should add the following instructions to the configuration file:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
            <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="???" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
            <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="???" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
            <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="???" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Attribute oldVersion contains the version being redirected (i.e. StyleCop versions that StyleCop+ is trying to load).
Attribute newVersion describes which version to use instead (i.e. your StyleCop version).

Examples

Using StyleCop+ with StyleCop 4.5.12.0 in Visual Studio 2010

  • Locate file C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config and add the following lines:
...
<configuration>
    ...
    <runtime>
        ...
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            ...
            <dependentAssembly>
                <assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.12.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.12.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.12.0" />
            </dependentAssembly>
            ...
        </assemblyBinding>
        ...
    </runtime>
    ...
</configuration>

Using StyleCop+ with StyleCop 4.5.11.0 in standalone Settings Editor

  • Create file C:\Program Files\StyleCop 4.5\StyleCopSettingsEditor.exe.config with the following contents:
<?xml version="1.0"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.11.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.11.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
                <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.5.11.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Last edited May 7, 2014 at 12:17 AM by shuruev, version 29

Comments

MattHeffron Feb 10, 2012 at 6:27 PM 
Just a note:
If you're running 64-bit Windows, then the "C:\Program Files\..." paths above should be "C:\Program Files (x86)\..."

juanalumni Feb 9, 2012 at 10:53 PM 
Worked like a charm with StyleCop 4.7.8!

Here are the contents in case its useful for anyone (assuming oldversion=4.7.5)

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.7.5.0-4.7.5.99" newVersion="4.7.8.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.7.5.0-4.7.5.99" newVersion="4.7.8.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.7.5.0-4.7.5.99" newVersion="4.7.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

shuruev Jan 27, 2011 at 3:11 PM 
Finally described it at http://stylecopplus.codeplex.com/wikipage?title=Quick%20Start%20Guide.
Thank you for the note!

dankesreiter Aug 31, 2010 at 12:54 PM 
I had some problem by using stylecop+ with my VS2010 (the StyleCopSettingsEditor.exe worked fine). The dll or its dependencies could not be found. The problem is caused by the rights management of downloaded assemblies, the detailed description and the solution could be found at http://cantgrokwontgrok.blogspot.com/2009/10/visual-studio-unknown-build-error.html.