{"id":20922,"date":"2018-09-18T16:13:10","date_gmt":"2018-09-18T16:13:10","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/vcblog\/?p=20922"},"modified":"2019-05-17T08:05:04","modified_gmt":"2019-05-17T08:05:04","slug":"parallel-custom-build-tools-in-visual-studio-2017","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/parallel-custom-build-tools-in-visual-studio-2017\/","title":{"rendered":"Parallel Custom Build Tools in Visual Studio 2017"},"content":{"rendered":"<p>Many projects need to use additional tools during their build to generate sources for further compilation or perform other custom build tasks. VC projects have always supported Custom Build Tool integration, but it had some limitations. One of the popular requests on UserVoice is <a href=\"https:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio-ide\/suggestions\/9604311-allow-custom-build-tools-to-run-in-parallel\">Allow custom build tools to run in parallel<\/a>. Another problem is that often custom build outputs need to be passed to other build tools (for instance, some tools can generate C\/C++ sources, which need to be passed to the compiler) and there was no easy way to specify that.<\/p>\n<p>To solve these problems, we added support for parallel execution of custom build tools and new options for easier build integration in Visual Studio 2017 15.8.<\/p>\n<p>Also, one of the most common build customizations is copying files. Before, we recommended using \u201cCustom Build Step\u201d or \u201cCustom Build Tool\u201d and specifying copy commands there. Now you can use simple Copy File options.<\/p>\n<h3>Custom Build Tool Options<\/h3>\n<p>If you are familiar with Custom Build Tool usage, you can skip this section and go to New Custom Build Tool Options.<\/p>\n<p>Custom Build Tool options are not visible in the \u201cProject Properties\u201d until you have at least one file using \u201cCustom Build Tool\u201d as its \u201cItem Type\u201d. You can set it in the file\u2019s \u201cGeneral\u201d properties:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image110.png\"><img decoding=\"async\" class=\"alignnone wp-image-20845 size-full\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image110.png\" alt=\"Custom Build Tool Item Type\" width=\"1231\" height=\"898\" \/><\/a><\/p>\n<p>As for other tools, you can set \u201cCustom Build Tool\u201d properties for each file, but usually it is easier to set them at the project configuration level, so they apply to all files which use \u201cCustom Build Tool\u201d. Note that you can use <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/msbuild\/msbuild-well-known-item-metadata\">MSBuild Well-known Item Metadata<\/a> there to specify file specific options. Unfortunately, you cannot use other item properties as they are not guaranteed to be defined before their usage.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image210.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20855\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image210.png\" alt=\"Custom Build Tool Properties\" width=\"1231\" height=\"856\" \/><\/a><\/p>\n<p><strong>Command Line<\/strong><\/p>\n<p>Specifies the command(s) to execute in cmd.exe. If you want several commands to be executed for the same file, you can add them to a script file or just enter them in the property editor, each command on a separate line:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image34.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20865\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image34.png\" alt=\"Custom Command Line\" width=\"578\" height=\"584\" \/><\/a><\/p>\n<p><strong>Description<\/strong><\/p>\n<p>Specifies a message to be printed before execution of the command(s), optional. It is added as \u2018\u2019echo\u201d command, so if you want to use \u201c&gt;\u201d symbol, it needs to be escaped: \u201c^&gt;\u201d.<\/p>\n<p><strong>Outputs<\/strong><\/p>\n<p>Specifies the output files the custom build tool generates.<\/p>\n<p><strong>Additional Dependencies<\/strong><\/p>\n<p>Specifies any additional input files to use for the custom build tool. Required for incremental build.<\/p>\n<p><strong>Link Objects<\/strong><\/p>\n<p>Specify whether the Inputs and outputs files with specific extensions (.obj, .lib, .res, .rsc) are passed to the linker.\nThis property was added in VS 2010 to maintain the behavior of pre-msbuild vc projects (VS 2009 and before) where file extensions determined which build action was performed on them.<\/p>\n<p>MSBuild is operating on items included into a particular named ItemGroup (Item Type), so we recommend using the new \u201cAdd Outputs to Item Type\u201d property instead.<\/p>\n<p><strong>Treat Output As Content<\/strong><\/p>\n<p>Specify whether the output file is a deployable content. Only used in projects supporting packaging (Universal Windows).<\/p>\n<p><strong>Content Root Folder<\/strong><\/p>\n<p>Content root folder to use for packaging.<\/p>\n<p><strong>Execute After, Execute Before<\/strong><\/p>\n<p>Define when to execute Custom Build Tool and Custom Build Step commands. For historical reasons they are executed at the same time.\nThe options are using msbuild target names, which requires you to have some understanding of msbuild targets execution order during build. There is a long list of the targets in the dropdown you can select from and you can type the target name there as well, but usually you just need to select one of the following targets which represent 3 main steps of C++ build:<\/p>\n<ul>\n<li>BuildGenerateSources<\/li>\n<li>BuildCompile<\/li>\n<li>BuildLink<\/li>\n<\/ul>\n<p>If your custom build needs to be executed in more precise time, you might need to look at your detailed (or binary) build log \u2013 you\u2019ll see all targets executed during build and their order.<\/p>\n<h3>New Custom Build Tool Options<\/h3>\n<p><strong>Add Outputs to Item Type<\/strong><\/p>\n<p>If you want custom build outputs to become inputs for another build operation, you can specify it here.<\/p>\n<p>For instance, if you want the outputs to be compiled, you need to add them to \u201cC\/C++ compiler\u201d item type. You also need to make Custom Build Tool to be executed before C\/C++ compilation by setting \u201cExecute After\u201d to \u201cBuildGenerateSources\u201d or \u201cExecute Before\u201d to \u201cBuildCompile\u201d.<\/p>\n<p><strong>Build in Parallel<\/strong><\/p>\n<p>Specifies that this item can be built in parallel with other custom build tool items.<\/p>\n<p><strong>Maximum Processes<\/strong><\/p>\n<p>Maximum number of CPU cores to use for parallel build. A value of 0 utilizes all available processors.<\/p>\n<p><strong>Maximum Batch size<\/strong><\/p>\n<p>Maximum number of items to execute together in one cmd.exe process during parallel build. A value of 0 divides items evenly into parallel batches. A value of 1 disables batching.\nLaunching a cmd.exe process takes some time, so larger batches will improve performance if the custom build tool processes items quickly. If your custom build takes significant time, disabling batching will give you better error reporting.<\/p>\n<h3>Copy File Options<\/h3>\n<p>If you need to copy a file to one or several locations during build, first you need to change its \u201cItem Type\u201d to \u201cCopy file\u201d and Apply. Then you\u2019ll see \u201cCopy File\u201d properties.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image41.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20875\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image41.png\" alt=\"Copy File Item Type\" width=\"1231\" height=\"898\" \/><\/a><\/p>\n<p>Again, you can define the options for individual files, or, if they are similar, for project configuration using <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/msbuild\/msbuild-well-known-item-metadata\">MSBuild Well-known Item Metadata<\/a>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image51.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20885\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/image51.png\" alt=\"Copy File Item Properties\" width=\"1231\" height=\"856\" \/><\/a><\/p>\n<p><strong>Destination Directories<\/strong><\/p>\n<p>You can specify one or several directories (separated by \u2018;\u2019) to copy the file to. The default is $(OutDir).<\/p>\n<p><strong>Destination File Name<\/strong><\/p>\n<p>You can specify the file name for the destination file(s). The default is the same as source: %(Filename)%(Extension).<\/p>\n<p>Other properties are the similar to Custom Build Tool and Custom Build step: you can set if the destination file(s) should be included into a package and when to copy the files during build.<\/p>\n<h3>Send Us Feedback<\/h3>\n<p>Please download <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/\">Visual Studio 2017 version 15.8<\/a> and try the new Custom Build Tool and Copy File functionality. We would love to know how it is working for you. Please give us feedback via the comments below or via email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>). For general issues please <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many projects need to use additional tools during their build to generate sources for further compilation or perform other custom build tasks. VC projects have always supported Custom Build Tool integration, but it had some limitations. One of the popular requests on UserVoice is Allow custom build tools to run in parallel. Another problem is [&hellip;]<\/p>\n","protected":false},"author":4347,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[230],"tags":[],"class_list":["post-20922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-new-feature"],"acf":[],"blog_post_summary":"<p>Many projects need to use additional tools during their build to generate sources for further compilation or perform other custom build tasks. VC projects have always supported Custom Build Tool integration, but it had some limitations. One of the popular requests on UserVoice is Allow custom build tools to run in parallel. Another problem is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/20922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/4347"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=20922"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/20922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=20922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=20922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=20922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}