首页 > 解决方案 > 从命令提示符获取 Windows nmake 版本?

问题描述

我真的不知道nmake,但我nmake在 Windows 10 下使用“x64 Native Tools Command Prompt for VS 2017”;我想从命令提示符中找出这个工具的版本。

我发现了这个:

https://docs.microsoft.com/en-us/cpp/build/reference/batch-mode-rules?view=vs-2019

要检查 NMAKE 版本,请运行 NMAKE 版本 1.62 或更高版本提供的 _NMAKE_VER 宏。此宏返回表示 Visual C++ 产品版本的字符串。

...但我真的不知道如何“运行宏” - 我试过这个:

C:\>nmake _NMAKE_VER

Microsoft (R) Program Maintenance Utility Version 14.16.27026.1
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make '_NMAKE_VER'
Stop.

因此,它删除了类似版本字符串的内容,但仍然存在错误。

因此,我怎样才能nmake正确地从命令行获取版本?

标签: windowscommand-promptnmake

解决方案


正如 Hans Passant 建议的那样,您可以考虑输入nmake/?; 这将为您提供您从问题中已经知道的内容,即14.16.27026.1.

该变量_NMAKE_VER的目的是允许您从 makefile 中测试版本nmakeVisual Studio 版本。例如,假设您的 makefile 是:

 # Check the first three characters of _NMAKE_VER to
 # obtain the Visual Studio version:
 !if [cmd /c if "%_NMAKE_VER:~0,3%"=="14." exit 1]
 !  message Using VS 2017, with NMAKE $(_NMAKE_VER)
 !elseif [cmd /c if "%_NMAKE_VER:~0,3%"=="12." exit 1]
 !  message Using VS 2013, with NMAKE $(_NMAKE_VER)
 !else
 !  message Unknown VS version, with NMAKE $(_NMAKE_VER)
 !endif

 # Just output _NMAKE_VER:
 all:
      @echo "Version             NMAKE" $(_NMAKE_VER)

然后从 Visual Studio 2017 开发人员命令提示符发出以下命令:

 nmake /nologo

将给出(在我的机器上):

 Using VS 2017, with NMAKE 14.10.25019.0
 Version             NMAKE 14.10.25019.0

或者对于 Visual Studio 2013:

 Using VS 2013, with NMAKE 12.00.21005.1
 Version             NMAKE 12.00.21005.1

我们需要使用 DOScmd来进行检查_NMAKE_VER,因为nmakegmake有限的字符串操作工具不同。

编辑:上述测试可能无法区分 VS 15 和 VS 17,因为 VS 17nmake版本号以14而不是预期的15.


推荐阅读