简体   繁体   English

如何在我的 vcxproj 文件中打印完整的 cl.exe 路径?

[英]How can I print full cl.exe path in my vcxproj file?

For a custom build target, I would like to have full path with correct version of cl.exe which is being called in ClCompile target.对于自定义构建目标,我希望拥有在 ClCompile 目标中调用的正确版本 cl.exe 的完整路径。

From retrieve path to cl.exe , I get it is %VCINSTALLDIR%\\bin\\x86\\Hostx86\\cl.exe or %VCINSTALLDIR%\\bin\\x64\\Hostx64\\cl.exe , But I do not want to write program for x84 vs x64 logic.检索路径到 cl.exe ,我得到它是%VCINSTALLDIR%\\bin\\x86\\Hostx86\\cl.exe%VCINSTALLDIR%\\bin\\x64\\Hostx64\\cl.exe ,但我不想为 x84 编写程序与 x64 逻辑。

In VCTargets\\Microsoft.CppCommon.Targets, I find that there is property ToolExe and ToolPath are being set to $(CLToolExe) and $(CLToolPath).在 VCTargets\\Microsoft.CppCommon.Targets 中,我发现 ToolExe 和 ToolPath 属性被设置为 $(CLToolExe) 和 $(CLToolPath)。

Overriding these properties also changed the path to compiler successfully for me, so it's correct that these are the properties names.覆盖这些属性也为我成功更改了编译器的路径,因此这些是属性名称是正确的。 Override Compiler in MSBuild 在 MSBuild 中覆盖编译器

But when I try printing %(CL.ToolPath) or $(CLToolPath) in my custom target exec class, it prints nothing.但是当我尝试在我的自定义目标 exec 类中打印 %(CL.ToolPath) 或 $(CLToolPath) 时,它什么也不打印。 I also looked in Visual Studio and couldn't find where it was being set.我还查看了 Visual Studio,但找不到它的设置位置。

Is there a variable which can provide cl.exe full path or is there any way I can print property ToolPath of CL Task in my custom target?是否有可以提供 cl.exe 完整路径的变量,或者有什么方法可以在我的自定义目标中打印 CL 任务的属性 ToolPath?

1) If you already uses the $(CLToolExe) and $(CLToolPath) to set your new cl.exe and then want to get the full path of it, you should use this $(CLToolPath)$(CLToolExe) to get the new value rather than %(CL.ToolPath) (there is no such way like this). 1)如果您已经使用$(CLToolExe)$(CLToolPath)来设置您的新cl.exe ,然后想要获取它的完整路径,您应该使用此$(CLToolPath)$(CLToolExe)来获取新的value 而不是%(CL.ToolPath) (没有这样的方式)。

This is my test result:这是我的测试结果:

Actually , you can overwrite these properties directly under your xxx.csporj file rather than in Microsoft.CppCommon.Targets file and when you build your project, it will use the new cl.exe .实际上,您可以直接在xxx.csporj文件下而不是在Microsoft.CppCommon.Targets文件中覆盖这些属性,当您构建项目时,它将使用新的cl.exe

CLToolExe

Then , I use a custom target to get the value:然后,我使用自定义目标来获取值:

<Target Name="test123" AfterTargets="ClCompile">
        <Exec Command="$(CLToolPath)$(CLToolExe)" />
        <Message Importance="high" Text="$(CLToolPath)$(CLToolExe)"></Message>
</Target>

在此处输入图片说明

2) If you did not change to the new value and use the default cl.exe without any changes, you should use $(ClCompilerPath) to get the default value. 2)如果你没有改成新的值,直接使用默认的cl.exe不做任何改动,应该使用$(ClCompilerPath)来获取默认值。

 <Target Name="test123" AfterTargets="ClCompile">       
       <Message Importance="high" Text="$(ClCompilerPath)"></Message>
 </Target>

在此处输入图片说明

Note : $(ClCompilerPath) cannot get the new value of $(CLToolPath)$(CLToolExe) since they are not related and can only get the default value.注意$(ClCompilerPath)无法获取$(CLToolPath)$(CLToolExe)的新值,因为它们没有关联,只能获取默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有完整路径的情况下强制cmake使用cl.exe? - How do I force cmake to use cl.exe without full path? 如何修复代码2退出的“ CL.exe” - How can I fix “CL.exe” exited with code 2 如何在 azure 应用服务中使用 cl.exe 编译 c++ 代码并生成可执行文件 - How can I use cl.exe in azure app service to compile c++ code and produce executable file 有什么办法可以确定我的代码是否正在用cl.exe编译? - Is there any way I can tell if my code is being compiled with cl.exe? 如何在 Visual Studio 2010 中捕获 cl.exe 命令行? - How can I capture the cl.exe command line in Visual Studio 2010? 如何使用 cl.exe 编译 Google 测试代码 - How Do I Compile Google Test Code With cl.exe 为 cl.exe 设置 output 路径 - Setting output path for cl.exe 如何使用从 cl.exe(Visual Studio C/C++ 编译器)生成的 a.exe 从命令行调试 a.exe? - How can I debug a .exe from the command line with a .exe generated from cl.exe (Visual Studio C/C++ Compiler)? 如何使用 Visual Studio C/C++ 编译器 (cl.exe) 来预处理我的 Objective-C 代码? - How can I use the Visual Studio C/C++ Compiler (cl.exe) to pre-process my objective-C code? 如何为我使用 cl.exe 手动编译的程序设置图标? - How do I set the icon for a program I compiled manually with cl.exe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM