VS2012 Impacts VS2010 Code Analysis - by Scott C Parillo

Status : 

 


5
0
Sign in
to vote
ID 771851 Comments
Status Active Workarounds
Type Bug Repros 1
Opened 11/21/2012 8:00:12 AM
Access Restriction Public

Description

I started a thread on http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/e7e9cff7-d451-43e8-8460-9c0a21dc87ba/ and was asked to create a Connect report by a code analysis moderator.

We have been developing with VS2010 for about 3 years now and use code analysis extensively. Our code analysis development environment consists of:

•We have a custom .targets file that ALL projects import before any Microsoft MSBuild import.
•We store a .ruleset file in TFS and use an MSBuild property 'CodeAnalysisRuleSetFullPath'  to construct the full path.
•Each project file includes <CodeAnalysisRuleSet>$(CodeAnalysisRuleSetFullPath)</CodeAnalysisRuleSet>. This is the only code analysis rules file used by our build system.
•The .rules file doesn't reference anything at all as far as I can tell.
•Each project file specifies TreatWarningsAsErrors.
•We employed GlobalSuppressions.cs for a large number of legacy projects. All newer projects use suppression attributes.

We're in the process of moving to VS2012 in a new TFS branch and haven't had any major issues; however, one of our team members attempted to build our most recent branch through VS2010 and experienced 238 code analysis warnings. As far as we can tell, these are the exact same code analysis warnings that we fixed in the newer VS2012 branch. Our expectation is that newer code analysis warnings are expected when using the newer tools but shouldn't impact the older VS2010 tools.

Our custom .rules file is straight-forward as we simply treat all CA warnings as errors. This is what the file looks like (only including 2 specific rules for brevity):

<?xml version="1.0" encoding="utf-8"?>
 <RuleSet Name="Microsoft All Rules Cause Errors" Description="Treat all warnings as errors." ToolsVersion="10.0">
   <IncludeAll Action="Warning" />
   <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
     <Rule Id="CA1000" Action="Error" />
     <Rule Id="CA1001" Action="Error" />
   </Rules>
 </RuleSet>

I was asked by a moderator to include full MSBuild diagnostics on one of the failed projects and this is the relevant snippet:

135>CodeAnalysisApplyLogFileXsl = false
 135>CodeAnalysisDictionaryFileName = CustomDictionary.xml
 135>CodeAnalysisDictionaryFullPath = E:\TFS\Sage Estimating\Development\Celilo\LinkedSource\CodeAnalysis\CustomDictionary.xml
 135>CodeAnalysisFailOnMissingRules = false
 135>CodeAnalysisForceOutput = true
 135>CodeAnalysisGenerateSuccessFile = true
 135>CodeAnalysisIgnoreGeneratedCode = true
 135>CodeAnalysisIgnoreInvalidTargets = true
 135>CodeAnalysisInputAssembly = E:\TFS\Sage Estimating\Development\Celilo\Runtime Files\Program Files\Sage Estimating\Estimating.Plugin.AddAdmin.dll
 135>CodeAnalysisLogFile = E:\TFS\Sage Estimating\Development\Celilo\Runtime Files\Program Files\Sage Estimating\Estimating.Plugin.AddAdmin.dll.CodeAnalysisLog.xml
 135>CodeAnalysisModuleSuppressionsFile = GlobalSuppressions.cs
 135>CodeAnalysisOutputToConsole = false
 135>CodeAnalysisOverrideRuleVisibilities = false
 135>CodeAnalysisPath = C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\
 135>CodeAnalysisQuiet = false
 135>CodeAnalysisRuleDirectories = ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules
 135>CodeAnalysisRuleSet = E:\TFS\Sage Estimating\Development\Celilo\LinkedSource\CodeAnalysis\AllRulesCauseErrors.ruleset
 135>CodeAnalysisRuleSetDirectories = ;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets
 135>CodeAnalysisRuleSetFileName = AllRulesCauseErrors.ruleset
 135>CodeAnalysisRuleSetFullPath = E:\TFS\Sage Estimating\Development\Celilo\LinkedSource\CodeAnalysis\AllRulesCauseErrors.ruleset
 135>CodeAnalysisSaveMessagesToReport = Active
 135>CodeAnalysisSearchGlobalAssemblyCache = true
 135>CodeAnalysisStaticAnalysisDirectory = C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\
 135>CodeAnalysisSucceededFile = E:\TFS\Sage Estimating\Development\Celilo\Runtime Files\Program Files\Sage Estimating\Estimating.Plugin.AddAdmin.dll.lastcodeanalysissucceeded
 135>CodeAnalysisSummary = false
 135>CodeAnalysisTargets = C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
 135>CodeAnalysisTimeout = 120
 135>CodeAnalysisTreatWarningsAsErrors = false
 135>CodeAnalysisUpdateProject = false
 135>CodeAnalysisUseTypeNameInSuppression = true
 135>CodeAnalysisVerbose = false

When I review the 'new' CA warnings that are being flagged, it's unclear why these were never raised in VS2010. These aren't new CA warnings at all as we have numerous examples throughout our 200+ projects of these same warnings.

Sign in to post a comment.
Posted by Microsoft on 4/26/2013 at 5:24 PM
Thanks for reporting this issue you've encountered with Visual Studio!

The behavior you're seeing is by design. As you pointed out, the code generated here has changed between .NET 4.0 and .NET 4.5, which has led to code analysis warnings in VS 2010. Unfortunately, your best bet here is to suppress this warning.

Alex Turner
Senior Program Manager
Visual Basic and C# Compiler
Posted by Jesse Houwing on 11/29/2012 at 4:26 AM
See also:

http://blog.jessehouwing.nl/2012/11/net-framework-sdk-45-changes-visual.html
Posted by Jesse Houwing on 11/29/2012 at 4:15 AM
From my investigations, this seems to be caused by the fact that the .NET 4.5 SDK generates slightly different code for WPF and WF component when compared to the code generated when you only have the .NET 4.0 SDK installed.

One of the differences I've observed is that the [GeneratedCode] attribute is no longer applied on the class level, but on the method level.

From what I can tell, these are not false positives under 2012, but false negatives under the original 2010/4.0 implementation.
Posted by Microsoft on 11/21/2012 at 9:57 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 11/21/2012 at 8:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)