如何在 Visual Studio 2019 中更改 %(DisableSpecificWarnings) [英] How to change %(DisableSpecificWarnings) in Visual Studio 2019

查看:106
本文介绍了如何在 Visual Studio 2019 中更改 %(DisableSpecificWarnings)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 VS 2019 后,我试图通过禁用一些我不关心的,例如 C26812 来使 C++ 警告再次有用

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

我知道我可以转到每个项目的属性页面并将此字符串添加到禁用特定警告"中,但这会重复太多(我有很多项目).因此,我尝试更改所有项目通用的 DisableSpecificWarnings 变量:4996;6031;%(DisableSpecificWarnings)

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)

如何以及在何处更改 Visual Studio 2019 中的此全局变量?

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

推荐答案

项目默认值来自多个 .props 文件,按范围、语言和平台组织.这些 .props 文件的位置(甚至存在)在版本之间发生了变化,并且可能取决于 VS 2019 之前安装的过去版本的历史记录.

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.

识别实际使用的默认 .props 的一种(更安全)方法是创建一个新的 C++ 项目并查看 <Import Project .../>.vcxproj 文件中的 code> 行.例如,我在我的机器上得到以下内容,按特异性递增.

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" />

最后一个应该是最具体的,带有每个用户每个平台的设置.它似乎不再是使用全新的 VS 2019 安装创建的,但它是从以前的版本继承而来的,并且在存在时仍然可以识别(请参阅 Microsoft.例如缺少 Cpp.Win32.user.props 文件).

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).

要查看 "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" 扩展为什么,打开项目设置并假装更改配置中的任何可编辑路径,然后单击下拉菜单中的Edit,并将.props 路径粘贴到编辑框中.实际路径将显示在其正下方,例如 C:\Users\\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props.

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.

找到磁盘上的文件,如果它不存在则创建它,并在Project/ItemDefinitionGroup/ClCompile下插入以下内容.

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>

如果 .props 文件不存在并且您必须从头开始创建它,则完整的文件将是:

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>

为了修改每台机器的默认值,而不是每用户的默认值,请按照相同的步骤操作,但使用 $(VCTargets) 文件之一.

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.

这篇关于如何在 Visual Studio 2019 中更改 %(DisableSpecificWarnings)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆