BUG: Multi-targeting rule not firing on usages of 2.0 SP2 and 3.0 SP2

Previously, I've spoken about the new multi-targeting rule that shipped in Visual Studio 2008 SP1 and FxCop 1.36. This rule helps to prevent users from inadvertently taking a dependency on a .NET service pack. Unfortunately, it shipped with a bug that when targeting .NET 3.5, prevented it from firing on usages of types and members only available in .NET 2.0 SP2 and .NET 3.0 SP2 (both installed by 3.5 SP1).

Luckily, the fix is rather simple.

In Visual Studio 2008 SP1:
  1. From an elevated (right-click and Run as administrator) Visual Studio command-prompt, type the following and press <ENTER>:

    devenv "%PROGRAMFILES%\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Repository\Compatibility\Desktop2.0SP2.xml"
  2. In the <CompatibilityEntry> element in the file that opens, change the Priority attribute from 3015 to 3515:
    <CompatibilityEntry Name=".NET Framework 2.0 Service Pack 2"
                        Platform="Desktop" 
                        Version="2.0.2" 
                        Priority="3515">
  3. Save the file.
  4. From the previously opened command-prompt, type the following and press <ENTER>:
    devenv "%PROGRAMFILES%\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Repository\Compatibility\Desktop3.0SP2.xml"

  5. Similar to above, in the <CompatibilityEntry> element, change the Priority attribute from 3020 to 3520:
    <CompatibilityEntry Name=".NET Framework 3.0 Service Pack 2"
                        Platform="Desktop" 
                        Version="3.0.2" 
                        Priority="3520">
  6. Save the file.
In FxCop 1.36:
  1. Follow the above steps, changing the paths above from %PROGRAMFILES%\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Repository\Compatibility to %PROGRAMFILES%\Microsoft FxCop 1.36\Repository\Compatibility.

 To verify the fix:

  1. In Visual Studio, start a new C# WPF Application, and paste the following code in the code-behind of App.xaml:
    public partial class App : Application
    {
        System.ComponentModel.DateTimeOffsetConverter field1;
        System.Windows.Data.BindingGroup field2;
    }
  2. In Solution Explorer, right-click on the project and choose Run Code Analysis.
  3. If the above steps were followed correctly, you should see warnings similar to the following:

    UseOnlyApiFromTargetedFramework 


This will be fixed in a future release of Visual Studio.

Thanks to Andrew Smith for bringing this my attention.

Published Saturday, November 29, 2008 7:00 AM by David Kean
Filed under: , ,