[英]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
。
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.