Skip to content
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

Feature: MSBuild switch for turning on/off analysis #23591

Closed
alexreg opened this issue Dec 5, 2017 · 4 comments
Closed

Feature: MSBuild switch for turning on/off analysis #23591

alexreg opened this issue Dec 5, 2017 · 4 comments

Comments

@alexreg
Copy link

alexreg commented Dec 5, 2017

It would be very handy to have an MSBuild property that switches on/off Roslyn code analysis, so you could so something like:

msbuild /p:RunRoslynAnalyzers=false MySolution.sln

This would work in a similar way to the old RunCodeAnalysis MSBuild property for pre-Roslyn code analysis.

@mavasani
Copy link
Contributor

mavasani commented Jul 2, 2019

Note that as a workaround, you can enable such functionality using a simple MSBuild target:

<Target Name="DisableAnalyzers"
BeforeTargets="CoreCompile"
Condition="'$(UseRoslynAnalyzers)' == 'false'">
<!--
Disable analyzers via an MSBuild property settable on the command line.
-->
<ItemGroup>
<Analyzer Remove="@(Analyzer)" />
</ItemGroup>
</Target>

@mavasani mavasani self-assigned this Jul 8, 2019
@mavasani mavasani modified the milestones: Backlog, 16.3 Jul 8, 2019
mavasani added a commit to mavasani/project-system that referenced this issue Jul 8, 2019
This page currently includes a new Roslyn Analyzers section with the following controls:
1. Hyperlinks for overview documentation on Roslyn analyzers and FxCopAnalyzers with install guidance
2. Check boxes to selectively disable analyzer execution during build and/or live analysis via project properties `RunRoslynAnalyzersDuringBuild` and `RunRoslynAnalyzersDuringLiveAnalysis`. Default values are 'true' for both of these. Addresses dotnet/roslyn#23591
3. Text box showing the installed FxCopAnalyzers NuGet package version, if any.
4. Following buttons:
   1. Install Latest: Installs the latest stable FxCopAnalyzers NuGet package.
   2. Install Custom: Opens NuGet package manager with "Microsoft.CodeAnalysis.FxCopAnalyzers" as the search string for custom installation.
   3. Uninstall: Uninstalls the currently installed FxCopAnalyzers NuGet package.
   4. Refresh: Refreshes the UI, in case user has done offline install/uninstall/upgrade of NuGet packages.

https://devdiv-design.visualstudio.com/D3%20Studio/_workitems/edit/7294 has the complete workflow with screenshots for the UI changes.

Addresses part of dotnet#266
@lgawel-cayan
Copy link

@mavasani We're having the same problem, where do we find roslyn/eng/targets/Imports.targets file?

@mavasani
Copy link
Contributor

mavasani commented Jul 11, 2019

@lgawel-cayan I meant you should create/change your targets file to copy that target so it runs for your project. You can also create a custom Directory.Build.targets: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019#directorybuildprops-and-directorybuildtargets and add this target to it.

mavasani added a commit to mavasani/project-system that referenced this issue Jul 19, 2019
This page currently includes a new Roslyn Analyzers section with the following controls:
1. Hyperlinks for overview documentation on Roslyn analyzers and FxCopAnalyzers with install guidance
2. Check boxes to selectively disable analyzer execution during build and/or live analysis via project properties `RunRoslynAnalyzersDuringBuild` and `RunRoslynAnalyzersDuringLiveAnalysis`. Default values are 'true' for both of these. Addresses dotnet/roslyn#23591
3. Text box showing the installed FxCopAnalyzers NuGet package version, if any.
4. Following buttons:
   1. Install Latest: Installs the latest stable FxCopAnalyzers NuGet package.
   2. Install Custom: Opens NuGet package manager with "Microsoft.CodeAnalysis.FxCopAnalyzers" as the search string for custom installation.
   3. Uninstall: Uninstalls the currently installed FxCopAnalyzers NuGet package.
   4. Refresh: Refreshes the UI, in case user has done offline install/uninstall/upgrade of NuGet packages.

https://devdiv-design.visualstudio.com/D3%20Studio/_workitems/edit/7294 has the complete workflow with screenshots for the UI changes.

Addresses part of dotnet#266
mavasani added a commit to mavasani/project-system that referenced this issue Jul 19, 2019
This page includes a new Roslyn Analyzers section with the following controls:
1. Hyperlink for overview documentation on Roslyn analyzers
2. Check boxes to selectively disable analyzer execution during build and/or live analysis via project properties `RunRoslynAnalyzersDuringBuild` and `RunRoslynAnalyzersDuringLiveAnalysis`. Default values are 'true' for both of these. Addresses dotnet/roslyn#23591. These properties will be respected once the targets change in https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/190487 makes it in.
3. Text box showing the installed FxCopAnalyzers NuGet package version, if any.
4. Following buttons:
   1. Install: Installs the known latest stable FxCopAnalyzers NuGet package (currently 2.9.3)
   2. Browse ('...'): Opens NuGet package manager with "Microsoft.CodeAnalysis.FxCopAnalyzers" as the search string for custom installation.
   3. Uninstall: Uninstalls the currently installed FxCopAnalyzers NuGet package.
   4. Refresh: Refreshes the UI, in case user has done offline install/uninstall/upgrade of NuGet packages.

https://devdiv-design.visualstudio.com/D3%20Studio/_workitems/edit/7294 has the complete workflow with screenshots for the UI changes.

Addresses part of dotnet#266
jjmew pushed a commit to dotnet/project-system that referenced this issue Jul 30, 2019
* Add Code Analysis property page

This page includes a new Roslyn Analyzers section with the following controls:
1. Hyperlink for overview documentation on Roslyn analyzers
2. Check boxes to selectively disable analyzer execution during build and/or live analysis via project properties `RunRoslynAnalyzersDuringBuild` and `RunRoslynAnalyzersDuringLiveAnalysis`. Default values are 'true' for both of these. Addresses dotnet/roslyn#23591. These properties will be respected once the targets change in https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/190487 makes it in.
3. Text box showing the installed FxCopAnalyzers NuGet package version, if any.
4. Following buttons:
   1. Install: Installs the known latest stable FxCopAnalyzers NuGet package (currently 2.9.3)
   2. Browse ('...'): Opens NuGet package manager with "Microsoft.CodeAnalysis.FxCopAnalyzers" as the search string for custom installation.
   3. Uninstall: Uninstalls the currently installed FxCopAnalyzers NuGet package.
   4. Refresh: Refreshes the UI, in case user has done offline install/uninstall/upgrade of NuGet packages.

https://devdiv-design.visualstudio.com/D3%20Studio/_workitems/edit/7294 has the complete workflow with screenshots for the UI changes.

Addresses part of #266

* Address feedback

* Remove the "Restore" button and instead enable auto-restore during property page activation. We only force restore packages now when user explicitly clicks Install/Uninstall button on the  UI

* Avoid using the code name "Roslyn" in the property page and MSBuild properties.
@mavasani
Copy link
Contributor

mavasani commented Aug 9, 2019

This is fixed in VS2019 16.3.

  1. For SDK style projects, you can configure analyzer execution using the new Code Analysis property page:
    image
  2. Alternatively, you can explicitly set the following MSBuild properties in the MSBuild project file:
    1. RunAnalyzersDuringBuild - true by default
    2. RunAnalyzersDuringLiveAnalysis - true by default
    3. RunAnalyzers - true by default. Setting it to false overrides both the prior properties and disable analyzers during both build and live analysis.

@mavasani mavasani closed this as completed Aug 9, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants