宏 $(VCTargetsPath) 究竟在哪里定义? [英] Where exactly is macro $(VCTargetsPath) defined?

查看:198
本文介绍了宏 $(VCTargetsPath) 究竟在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们之前讨论过.

只是MSBuild 中的各种targetsprops 文件是嵌套且相互关联的.VCTargetsPath 被设置为 _VCTargetsPathForToolset 属性的值,而 _VCTargetsPathForToolset 在另一个关联的 targetsprops 中定义 文件.

一般,使用 在当前 targetsprops 文件中嵌入另一个文件.

而且MSBuild中的文件太多了,如果你想逐层搜索直到找到最终的具体值,可能看起来有点复杂.

除此之外VCTargetsPathMSBuild用来编译c++项目的一些工具的路径.

VS2019 中的默认值为 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160.>

您可以在 xxx.vcxproj 文件中编写自定义目标以输出其值.

1)xxx.vcxproj 文件中写入:

<消息重要性=高"文本=$(VCTargetsPath)"></Message></目标>

2) 然后重建您的项目,您可以看到:

ItMSBuild 系统定义的路径.随便改的话,会导致项目编译不通过,除非你有一套类似MSBuild的自定义系统来构建C++项目,然后放到新的路径下,让新路径覆盖 VCTargetsPath 属性.

另外,我很好奇你为什么要找到最低的VCTargetPath值.如果你想知道它的原理,上面的回答就说明了.

并且如果你想覆盖它的值,你可以直接创建一个名为VCTargetsPath环境系统变量,然后设置它的值到一个新的.

重新启动 VS 以启用此类新值.这比修改 targets 文件要容易得多.

We had a discussion before.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e04e7791-c0c4-4598-b900-310878f5af45/how-can-i-locate-and-change-the-vctargetspath-variable?forum=msbuild

After hours searching .props files, all the $(VCTargetsPath) in .prop and .targets are deleted, but Visual Studio can still recognize this macro/variable correctly.

By modifing Microsoft.Cpp.ToolsetLocation.props, $(VCTargetsPath) can be modified and in consequence VS can no longer create new project.

So, where exactly this macro defined?

I believed that this macro is not and shouldn't be hardcoded.

解决方案

Where exactly is macro $(VCTargetsPath) defined?

Actually, VCTargetsPath property is defined in the MSBuild system props or targets files under MSBuild folder(C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild). And the files are nested and related to each other. Therefore, the values of various properties are referred to each other in the level-by-level files, and the value of VCTargetsPath is no exception.

==========================================================================

MSBuild is actually equivalent to soft coding. Once MSBuild is installed, it exists as a bunch of dlls and various established props and targets files. You can modify its properties or extend its functions in various ways in the props or targets file. The MSBuild itself is an open source build tool. It is not as unchangeable as you think.

==========================================================================

The VCTargetsPath is actually defined in the msbuild props file called Microsoft.Cpp.ToolsetLocation.props as you said.

It's just that the various targets and props files in MSBuild are nested and interrelated. VCTargetsPath is set as the value of _VCTargetsPathForToolset property while _VCTargetsPathForToolset is defined in another associated targets or props file.

In general, use <import projects="xxxx\xxx.props or targets" /> to embed another file in the current targets or props file.

And there are so many files in MSBuild that if you want to search layer by layer until you find the final specific value, it might seem a little complicated.

Besides, VCTargetsPath is the path of some tools used by MSBuild to compile c++ projects.

The default value in VS2019 is C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160.

You can write a custom target in the xxx.vcxproj file to output its value.

1) write this in xxx.vcxproj file:

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

2) Then rebuild your project and you can see this:

It is the MSBuild system defined path. If you change it easily, it will cause the project to fail to compile, unless you have a set of self-defined system similar to MSBuild to build C++ projects, and then put it in new path, let the new path overwrite VCTargetsPath property.

In addition, I am curious why you want to find the lowest VCTargetPath value. If you want to know the principle of it, the above answer explains it.

And if you want to overwrite its value, you can just create an environment system variable called VCTargetsPath directly, and then set its value to a new one.

Restart VS to enable such new value. It is much easier than modifying the targets file.

这篇关于宏 $(VCTargetsPath) 究竟在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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