question

TomW2673 avatar image
0 Votes"
TomW2673 asked TomW2673 commented

VSIX - Set RunAnalyzers property in code

Using the following code, we are able to set the CodeAnalysisRuleSet XML node in a *.csproj file:

EnvDTE.Project project;
foreach (Configuration c in project.ConfigurationManager)
{
c.Properties.Item("CodeAnalysisRuleSet").Value = filename;
}

Now we would like to do the same for the "RunAnalyzers" property, but we get an exception when we try to set the property. Probably that property is not exposed through the EnvDTE.Project object.

c.Properties.Item("RunAnalyzers").Value = true;

Does somebody know the correct way to achieve this please? The intention is to be able to turn on and of code analysis from withing an extension.

dotnet-csharpvs-msbuildvs-extensions
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TomW2673 ,

Was the thrown exception a ArgumentException exception? Besides, refer to this doc: RunAnalyzers, looks like the default value of RunAnalyzers property is true.

Best Regards,
Tianyu

0 Votes 0 ·

It was indeed an ArgumentException. The default value of RunAnalyzers is indeed true, but we want to set it to false in some cases.

0 Votes 0 ·

Hi @TomW2673 , perhaps you can try to use this IVsBuildPropertyStorage2 interface.

1 Vote 1 ·

0 Answers