1

After upgrading to VS 2019 I'm trying to make the C++ warnings useful again by disabling some that I don't care about, for example C26812

I know I could go to every project's property page and add this string to "Disable Specific Warnings" but that would be too much duplication (I've got a lot of projects). So instead I'm trying to change the DisableSpecificWarnings variable which is common to all Projects: 4996;6031;%(DisableSpecificWarnings)

How and where can I change this global variable in Visual Studio 2019 ?

Axel Podehl
  • 4,034
  • 29
  • 41
  • Assuming C++ lookup `Microsoft.Cpp.Default.props` in `$(VCTargetsPath)` ("C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0" by default). – dxiv Jun 05 '20 at 07:45
  • C:\Program Files (x86)\MSBuild only has a Microsoft folder, not a Microsoft.Cpp – Axel Podehl Jun 05 '20 at 11:43
  • The exact locations depend on version, upgrade history and *other* components being installed. The full story is too long for a comment so I posted it as an answer below. – dxiv Jun 05 '20 at 16:51

2 Answers2

1

For anyone interested, I ended up creating one GLOBAL.props file which is shared across projects.

To add this sheet, select project go to "Property Manager", select the Project and do "Add Existing Property Sheet". For example DisableSpecificWarnings used by all sub-projects is defined here. For further information on Compile and Link properties, see MSBuild documentation:

Clcompile: https://learn.microsoft.com/en-us/visualstudio/msbuild/cl-task?view=vs-2019

Link: https://learn.microsoft.com/en-us/visualstudio/msbuild/link-task?view=vs-2019

  <?xml version="1.0" encoding="utf-8"?>
  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <DisableSpecificWarnings>4675;4541;4702;4267;4996;26812;%(DisableSpecificWarnings)</DisableSpecificWarnings>
    </ClCompile>
  </ItemDefinitionGroup>
  <ItemGroup />
  </Project>
Axel Podehl
  • 4,034
  • 29
  • 41
0

Project defaults come from several .props files, organized by scope, language and platform. The location (and even presence) of those .props files has changed between versions, and can depend on the history of past versions installed prior to VS 2019.

One (safer) way to identify the default .props being actually used is to create a new C++ project and look at the <Import Project ... /> lines in the generated .vcxproj file. For example, I am getting the following on my machine, in increasing order of specificity.

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />

The last one is supposed to be the most specific, carrying the per-user per-platform settings. It appears to no longer be created with fresh VS 2019 installs, but it is inherited from prior versions and is still recognized when present (see Microsoft.Cpp.Win32.user.props file missing for example).

To see what "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" expands to, open the project settings and pretend to change any of editable paths in the configuration, then click Edit in the dropdown menu and paste the .props path in the edit box. The actual path will show right below it, for example C:\Users\<user name>\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props.

Find the file on disk, or create it if it doesn't exist already, and insert the following under Project/ItemDefinitionGroup/ClCompile.

      <DisableSpecificWarnings>26812;%(DisableSpecificWarnings)</DisableSpecificWarnings>

If the .props file did not exist and you had to create it from scratch, the complete file would be:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemDefinitionGroup>
    <ClCompile>
      <DisableSpecificWarnings>26812;%(DisableSpecificWarnings)</DisableSpecificWarnings>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

In order to modify the per-machine defaults, rather than the per-user ones, follow the same steps but use one of the $(VCTargets) files instead.

dxiv
  • 16,984
  • 2
  • 27
  • 49
  • 1
    Thanks for the detailed answer. I understood more about this process by reading it. However I ended up going through https://learn.microsoft.com/en-us/cpp/build/create-reusable-property-configurations?view=vs-2019 and add a new (shared) GLOBAL.props – Axel Podehl Jun 11 '20 at 09:50