Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

mavasani
Copy link
Contributor

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:

  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.

Performance impact

None

Is this a regression from a previous update?

Root cause analysis:

New feature

How was the bug found?

Dogfooding

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
@mavasani
Copy link
Contributor Author

Tagging @dotnet/project-system for review

Copy link
Member

@333fred 333fred left a 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected AbstractRunCodeAnalysisCommand(
UnconfiguredProject unconfiguredProject,
IProjectThreadingService threadingService,
SVsServiceProvider serviceProvider,
Copy link
Member

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);
Copy link
Member

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to UI thread.

Copy link
Member

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);
Copy link
Member

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">
Copy link
Member

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?

@davkean
Copy link
Member

davkean commented Jan 18, 2017

Does FxCop work for .NET Core projects?

@mavasani
Copy link
Contributor Author

It succeeds for projects targeting desktop framework, but fails for apps targeting netcoreapp1.0 as the assembly references System.Runtime 4.1.0.0:

Could not identify platform for 'c:\users\mavasani\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\netcoreapp1.0\ClassLibrary1.dll'.

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.

@srivatsn
Copy link
Contributor

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.

@srivatsn
Copy link
Contributor

Closing this PR as I don't think this is the right direction.

@srivatsn srivatsn closed this Jan 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable code analysis
5 participants