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:
- 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"
- 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"
- Save the file.
- 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"
- Similar to above, in the <CompatibilityEntry> element, change the Priority attribute from 3020 to 3520:
<CompatibilityEntry Name=".NET Framework 3.0 Service Pack 2"
- Save the file.
In FxCop 1.36:
- 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:
- 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
- In Solution Explorer, right-click on the project and choose Run Code Analysis.
- If the above steps were followed correctly, you should see warnings similar to the following:
This will be fixed in a future release of Visual Studio.
Thanks to Andrew Smith for bringing this my attention.