.NET Framework SDK 4.5 changes Visual Studio 2010 Code Analysis and FxCop


There have been a few reports in the MSDN forums[1][2] that Code Analysis 2010 or FxCop 10 will trigger more often after installing Visual Studio 2012 or the .NET Framework SDK 4.5 along side Visual Studio 2010. There's also a bug on Connect[3][4] that follows this. This isn't caused due to Visual Studio 2010 suddenly using the 2012 version of FxCop or anything like that. It's actually caused by differences in the code being generated.

The issues that are detected, are actually issues that went undetected before due to the way .NET 4.0 generates code. In .NET 4.0 the code generated for a WPF custom control, for example, will have the [GeneratedCode] attribute at the class level. After installing the .NET 4.5 SDK this attribute is applied to the method level, instead. This post on the MSDN forums captures the differences really well:

Unless you're enforcing naming conventions using FxCop, the newer generated code will actually result in better checks of your existing .NET 4.0 code, but it will cause havoc when you're in a team that uses Visual Studio 2010 to edit the same controls, but some members also have Visual Studio 2012 installed, since the generated code will be different depending on who last edited the files. This is also going to be great fun when merging ;).

As to be expected, other tools that ignore Generated Code, such as StyleCop, Code Metrics and Code Coverage will be impacted by this change.

Search This Blog


Most Reading