VCCLCompilerTool.EnablePREfast Property
Visual Studio 2015
Gets or sets whether Native Code Analysis is enabled.
Assembly: Microsoft.VisualStudio.VCProjectEngine (in Microsoft.VisualStudio.VCProjectEngine.dll)
Additional options can be set using the AdditionalOptions property.
Note |
|---|
/analyze is only available in Enterprise (Team Developer) versions for x86 compilers. |
The following example demonstrates how to use the EnablePREfast and AdditionalOptions properties to set the /analyze:WX- switch. (Both properties are required to do this.) Specifying /analyze:WX- means that code analysis warnings will not be treated as errors when compiling with /WX. For more information, see /analyze (Code Analysis).
// Add references to Microsoft.VisualStudio.VCProjectEngine and // System.Windows.Forms. using System; using Extensibility; using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.VCProjectEngine; using System.Text; using System.Windows.Forms; public void EnablePREfastExample(DTE2 dte) { try { VCProject prj; IVCCollection cfgs, tools; VCConfiguration cfg; VCCLCompilerTool tool; StringBuilder sb = new StringBuilder(); prj = (Microsoft.VisualStudio.VCProjectEngine.VCProject) dte.Solution.Projects.Item(1).Object; cfgs = (Microsoft.VisualStudio.VCProjectEngine.IVCCollection) prj.Configurations; cfg = (Microsoft.VisualStudio.VCProjectEngine.VCConfiguration) cfgs.Item(1); tools = (Microsoft.VisualStudio.VCProjectEngine.IVCCollection) cfg.Tools; tool = (Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool) tools.Item("VCCLCompilerTool"); sb.Length = 0; sb.Append("Current project PREfast setting: " + tool.EnablePREfast + Environment.NewLine); sb.Append("Flag: " + tool.AdditionalOptions); MessageBox.Show(sb.ToString()); // Toggle PREfast setting. if (!(tool.EnablePREfast == true)) { // PREfast is not enabled. Turn it and the WX- flag on. tool.EnablePREfast = true; tool.AdditionalOptions = "/analyze:WX-"; } else { // Toggle the opposite. tool.EnablePREfast = false; tool.AdditionalOptions = "/analyze:WX"; } sb.Length = 0; sb.Append("New project PREfast setting: " + tool.EnablePREfast + Environment.NewLine); sb.Append("Flag: " + tool.AdditionalOptions); MessageBox.Show(sb.ToString()); } catch (System.Exception errmsg) { MessageBox.Show("ERROR! " + errmsg.Message); } }
Show:
