VS2017从15.4.1升级到15.5.1导致构建错误

Upgrading VS2017 from 15.4.1 to 15.5.1 resulted in build error

我正在使用以下 tools/versions 进行编程:Windows 10 / VS2017 Professional / C++

升级到 15.5.1 后出现以下错误:

MIDL2338: switches are contradictory - no_robust vs. - target

Microsoft 编译器错误描述列表说:编译 IDL 文件时不能同时使用 /osf 和 /ms_ext 命令行开关。

None 个开关在我的项目属性中指定。

我尝试降级回 15.4.1,但发现除非是 N-1,否则无法恢复到旧版本。这是基于我读过的许多博客(包括 Stack Overflow)。

我遇到了瓶颈,一直处于停滞状态,直到我弄清楚这个开关问题。

非常感谢您的帮助。

我 运行 刚刚遇到同样的问题,但幸运的是我可以访问另一个较旧的安装。

这里是VS 2017 15.4.4下的命令行:

/iid "RtdHandleServer_i.c" /env win32 /h "RtdHandleServer.h" /W1 /char signed /tlb "Win32\Release\RtdHandleServer.tlb" /Oicf /D "NDEBUG" /no_robust /nologo /proxy "RtdHandleServer_p.c" 

这是在 VS 2017 15.5.1 下更改为:

/iid "RtdHandleServer_i.c" /env win32 /h "RtdHandleServer.h" /W1 /char signed /tlb "Win32\Release\RtdHandleServer.tlb" /Oicf /target "NT60" /D "NDEBUG" /no_robust /nologo /proxy "RtdHandleServer_p.c" 

所以所有改变的是添加了一个新参数 /target "NT60",大概是一个新的默认值。

在我看来有两种方法可以解决这个问题:

  1. 在 idl 文件的 属性 页面对话框中,转到配置属性 > MIDL > 高级,并清除“最小目标系统”的值。
  2. 去掉 -no_robust 标志。根据文档 (https://msdn.microsoft.com/en-us/library/windows/desktop/aa367349%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396):

"The /no_robust command line switch must be used to disable the /robust feature if generated stubs need to run on Microsoft Windows NT, Windows 95/98, or Windows Me."

就消除错误而言,这两种更改对我都有效,但第一种方法的影响最小。

PS。我认为 MS 错误描述 (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366756%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) 在这种情况下很可能不正确。您看到的原始错误消息指的是两个特定标志,/no_robust/target,而不是 /osf/ms_ext.

注意: MIDL 编译器 /robust 开关执行以下操作 (Microsoft docs MIDL compiler: /robust switch)

Using the /robust switch generates additional information that allows the Network Data Representation (NDR) engine to perform run-time error checking on correlated arguments in dynamic arrays, unions, and in out interface pointers in DCOM applications. The /robust switch is only available under Windows 2000 and later versions of Windows.

为了删除 /no_robust 标志(如果生成的存根在 Microsoft Windows NT 上不需要 运行,Windows 95/98,或者Windows我),只需删除

<ValidateAllParameters>false</ValidateAllParameters>

.vcxproj 文件中 <Midl> 元素下的条目。

来源:ref

MIDL2338 与 MIDL1024 错误的另一个参考答案。 https://developercommunity.visualstudio.com/t/build-fails-from-from-msbuild-command-line-with-er/207580