• <bdo id='ObGwL'></bdo><ul id='ObGwL'></ul>
  • <i id='ObGwL'><tr id='ObGwL'><dt id='ObGwL'><q id='ObGwL'><span id='ObGwL'><b id='ObGwL'><form id='ObGwL'><ins id='ObGwL'></ins><ul id='ObGwL'></ul><sub id='ObGwL'></sub></form><legend id='ObGwL'></legend><bdo id='ObGwL'><pre id='ObGwL'><center id='ObGwL'></center></pre></bdo></b><th id='ObGwL'></th></span></q></dt></tr></i><div id='ObGwL'><tfoot id='ObGwL'></tfoot><dl id='ObGwL'><fieldset id='ObGwL'></fieldset></dl></div>

    <small id='ObGwL'></small><noframes id='ObGwL'>

    <legend id='ObGwL'><style id='ObGwL'><dir id='ObGwL'><q id='ObGwL'></q></dir></style></legend>

    <tfoot id='ObGwL'></tfoot>

      1. 如何覆盖 Visual Studio 2017 社区的编译命令

        How to override compile command of Visual Studio 2017 Community(如何覆盖 Visual Studio 2017 社区的编译命令)
            <bdo id='JGB1t'></bdo><ul id='JGB1t'></ul>
              <tbody id='JGB1t'></tbody>

            <small id='JGB1t'></small><noframes id='JGB1t'>

            <i id='JGB1t'><tr id='JGB1t'><dt id='JGB1t'><q id='JGB1t'><span id='JGB1t'><b id='JGB1t'><form id='JGB1t'><ins id='JGB1t'></ins><ul id='JGB1t'></ul><sub id='JGB1t'></sub></form><legend id='JGB1t'></legend><bdo id='JGB1t'><pre id='JGB1t'><center id='JGB1t'></center></pre></bdo></b><th id='JGB1t'></th></span></q></dt></tr></i><div id='JGB1t'><tfoot id='JGB1t'></tfoot><dl id='JGB1t'><fieldset id='JGB1t'></fieldset></dl></div>

              1. <tfoot id='JGB1t'></tfoot>
                  <legend id='JGB1t'><style id='JGB1t'><dir id='JGB1t'><q id='JGB1t'></q></dir></style></legend>

                  本文介绍了如何覆盖 Visual Studio 2017 社区的编译命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用一个简单的 shell 脚本覆盖默认的 Visual Studio C++ 编译器.我想要的是捕获参数,例如文件名,并创建一些统计信息.但是我想完全覆盖编译过程 - 也就是说,我想从我的 shell 脚本中调用原始编译.

                  I would like to override the default Visual Studio C++ compiler with a simple shell script. What I want is to capture the arguments, such as file name, and create some statistics. However I want to override the compilation process completely - that is, I want to call the original compilation from my shell script.

                  我用谷歌搜索,但我发现的只是如何在项目中执行预构建和构建后脚本.那不是我想要的.

                  I googled but all I found was how to have pre-build and post-build scripts that execute within a project. That's not what I want.

                  我想在全球范围内改变这一点.我该怎么做?

                  I want to change this globally. How can I do it?

                  推荐答案

                  对于标准的 C++ 项目文件编译是通过调用 MsBuild 目标 名为 ClCompile.请注意,还有一个名为 ClCompile 的 MsBuild Item 列出了实际的使用 C++ 源文件,通过在文本编辑器中打开 .vcxproj 可以很容易地看到这一点.因此,此 ClCompile 项用于 ClCompile 目标,并在其中传递给 CL 任务 依次调用 cl.exe,实际编译器可执行文件.此代码可以在您使用的工具集的 Microsoft.CppCommon.targets 文件中找到,用于在 C:Program Files (x86)Microsoft Visual Studio2017Community 的 64 位机器上默认安装 VS2017 社区Common7IDEVCVCTargetsMicrosoft.CppCommon.targets.

                  For a standard C++ project file compilation is done by invoking the MsBuild Target named ClCompile. Note there's also an MsBuild Item named ClCompile which lists the actual C++ source files used, this can be readily seen by opening your .vcxproj in a text editor. Consequently this ClCompile Item is used in the ClCompile Target, where it gets passed to the CL Task which in turn will invoke cl.exe, the actual compiler executable. This code for this can be found in the Microsoft.CppCommon.targets file for the toolset you use, for a default install of VS2017 community on a 64bit machine that is C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDEVCVCTargetsMicrosoft.CppCommon.targets.

                  这 3 个中的任何一个都可以用自定义版本覆盖,但是因为您认为仅替换磁盘上的 cl.exe 并不是最好的主意.

                  Any of those 3 could be overridden with a custom version however as you figured already just replacing cl.exe on disk isn't the best idea.

                  但是 CL 可以简单地通过覆盖 CLToolExe 和 CLToolPath 来使用任何可执行文件 属性.实际上:打开您的 .vcxproj 文件并添加

                  But CL can use any executable simply by overriding the CLToolExe and CLToolPath properties. Practically: open your .vcxproj file and add

                  <PropertyGroup>
                    <CLToolExe>mycl.exe</CLToolExe>
                    <CLToolPath>c:path	omycompilerstub</CLToolPath>
                  </PropertyGroup>
                  

                  一直到最后,在导入Microsoft.Cpp.targets的那一行之后;将调用 mycl.exe 而不是 cl.exe.如果您希望在您的机器上全局获得相同的效果,您可以将该 PropertyGroup 放在一个单独的 msbuild 文件中并将其保存在例如 C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDEVCVCTargetsPlatformsx64ImportAfterMyCustomImport.targets.该目录中的任何目标文件都将自动导入.

                  all the way at the end, after the line importing Microsoft.Cpp.targets; mycl.exe will be called instead of cl.exe. If you want the same effect globally on your machine, you'll put that PropertyGroup in a seperate msbuild file and save it in for example C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDEVCVCTargetsPlatformsx64ImportAfterMyCustomImport.targets. Any targets file in that directory will be imported automatically.

                  作为替代方案,您可以覆盖 ClCompile 目标或 CL 任务.不过,这更复杂,例如对于 ClCompile,您首先要复制 Microsoft.CppCommon.targets 中的整个实现,然后添加您需要的任何逻辑.优点是您可以直接访问例如源文件等,而无需解析命令行.例如,这将覆盖 ClCompile 并打印源文件并将它们传递给自定义可执行文件:

                  As an alternative you could override the ClCompile target or the CL task. That's more involved though, e.g. for ClCompile you'd start by copying the whole implementation found in Microsoft.CppCommon.targets and then add whatever logic you need. Advantage is you have direct access to e.g. source files etc without having to parse a command line. For example this would override ClCompile and print source files and pass them to a custom executable:

                  <Target Name="ClCompile"
                          Condition="'@(ClCompile)' != ''"
                          DependsOnTargets="SelectClCompile">
                  
                    <Message Text="All the sources = @(ClCompile)"/>
                    <Exec Command="mycustom.exe @(ClCompile)" />
                  
                    ... <!--rest of implementation copied from Microsoft.CppCommon.targets goes here-->
                  </Target>
                  

                  同样,这需要放在项目文件的末尾或 ImportAfter 目录中以进行全局覆盖.

                  Again, this needs to be put at the end of your project file or in the ImportAfter directory for global overriding.

                  这篇关于如何覆盖 Visual Studio 2017 社区的编译命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
                    <tbody id='HUjcR'></tbody>

                  1. <legend id='HUjcR'><style id='HUjcR'><dir id='HUjcR'><q id='HUjcR'></q></dir></style></legend>
                      • <bdo id='HUjcR'></bdo><ul id='HUjcR'></ul>
                            <tfoot id='HUjcR'></tfoot>
                          • <i id='HUjcR'><tr id='HUjcR'><dt id='HUjcR'><q id='HUjcR'><span id='HUjcR'><b id='HUjcR'><form id='HUjcR'><ins id='HUjcR'></ins><ul id='HUjcR'></ul><sub id='HUjcR'></sub></form><legend id='HUjcR'></legend><bdo id='HUjcR'><pre id='HUjcR'><center id='HUjcR'></center></pre></bdo></b><th id='HUjcR'></th></span></q></dt></tr></i><div id='HUjcR'><tfoot id='HUjcR'></tfoot><dl id='HUjcR'><fieldset id='HUjcR'></fieldset></dl></div>

                            <small id='HUjcR'></small><noframes id='HUjcR'>