-
Notifications
You must be signed in to change notification settings - Fork 396
Enable "Run Code Analysis" commands to run FxCop for managed projects #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1. Mimic the behavior of native project system to load stancore package for code analysis, if installed. 2. Turn on the CodeAnalysis specific global build properties for enabling FxCop when build is invoked from Run Code Analysis. Fixes dotnet#988
Tagging @dotnet/project-system for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs some tests as well.
public const long RunCodeAnalysisTopLevelBuildMenuCmdId = 0x066f; | ||
public const long RunCodeAnalysisProjectContextMenuCmdId = 0x0670; | ||
public const string CodeAnalysisPackageGuid = "B20604B0-72BC-4953-BB92-95BF26D30CFA"; | ||
public const string VSStd2KCommandSet = "1496A755-94DE-11D0-8C3F-00C04FC2AAE2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and could you put the CmdId's with the existing ones, https://github.com/dotnet/roslyn-project-system/blob/master/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Input/VisualStudioStandard2kCommandId.cs
protected AbstractRunCodeAnalysisCommand( | ||
UnconfiguredProject unconfiguredProject, | ||
IProjectThreadingService threadingService, | ||
SVsServiceProvider serviceProvider, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We normally do this as [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider
private async Task<bool> IsReadyToBuildAsync() | ||
{ | ||
// Ensure build manager is initialized. | ||
await EnsureBuildManagerInitializedAsync().ConfigureAwait(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the ConfigureAwait(true)
here? I don't believe you're coming from a specific thread on this.
// Ensure build manager is initialized. | ||
await EnsureBuildManagerInitializedAsync().ConfigureAwait(true); | ||
|
||
ErrorHandler.ThrowOnFailure(_buildManager.QueryBuildManagerBusy(out int busy)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to UI thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just switch above EnsureBuildManagerInitializedAsync()
, then the ConfigureAwait
will matter.
// Build manager APIs require UI thread access. | ||
await _threadingService.SwitchToUIThread(); | ||
|
||
await EnsureCodeAnalysisPackageLoadedAsync().ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigureAwait(true)
@@ -276,4 +276,10 @@ In order to debug this project, add an executable project to this solution which | |||
<data name="XprojMigrationGeneralFailure" xml:space="preserve"> | |||
<value>Failed to migrate XProj project {0}. '{1}' exited with error code {2}.</value> | |||
</data> | |||
<data name="RunCodeAnalysisProjectContextMenuCommand" xml:space="preserve"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not an existing command with existing text?
Does FxCop work for .NET Core projects? |
It succeeds for projects targeting desktop framework, but fails for apps targeting netcoreapp1.0 as the assembly references System.Runtime 4.1.0.0:
It goes past this failure for netstandard targeting assemblies as it references System.Runtime 4.0.20.0, which is handled http://index/?leftProject=Microsoft.VisualStudio.CodeAnalysis.Common&leftSymbol=kawcj4j5z2rb&file=PortablePlatform.cs&line=34, but the assembly isn't implicitly found. Sri told me this won't meet the RTW bar as we will need fixes in multiple places, including FXCop. |
Yes getting FxCop to work for Netcore projects is a bunch of work and I'd rather spend that energy on getting the fxcopanalyzers working well. I think we shouldn't take this PR. |
Closing this PR as I don't think this is the right direction. |
Customer scenario
Users cannot run Code Analysis (FxCop) from Visual Studio.
Bugs this fixes:
Fixes #988
Workarounds, if any
Run FxCop from CommandLine
Risk
This is new code, so it shouldn't affect existing features. The change involves:
Performance impact
None
Is this a regression from a previous update?
Root cause analysis:
New feature
How was the bug found?
Dogfooding