{"id":33437,"date":"2024-01-08T16:21:52","date_gmt":"2024-01-08T16:21:52","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=33437"},"modified":"2024-01-08T16:21:52","modified_gmt":"2024-01-08T16:21:52","slug":"include-diagnostics-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/include-diagnostics-in-visual-studio\/","title":{"rendered":"#include Diagnostics\u00a0in Visual Studio"},"content":{"rendered":"<p><span data-contrast=\"auto\">We\u2019re excited to announce that the #include Diagnostics feature is now available in Visual Studio 2022 17.9 Preview 2. This new feature allows you to better understand the behavior of #include directives by providing detailed information on each directive\u2019s references and build time.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\" target=\"_blank\">Download Visual Studio Preview<\/a><\/div><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-33440\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1.png\" alt=\"Image include diagnostics context menu\" width=\"2186\" height=\"515\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1.png 2186w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1-300x71.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1-1024x241.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1-768x181.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1-1536x362.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_context_menu-1-2048x482.png 2048w\" sizes=\"(max-width: 2186px) 100vw, 2186px\" \/><\/a><\/p>\n<p><span data-contrast=\"auto\">To begin utilizing this feature, activate <\/span><b><span data-contrast=\"auto\">#include diagnostics<\/span><\/b><span data-contrast=\"auto\"> by performing a right-click in your editor to display the context menu. Then, navigate to the \u2018Include Directives\u2019 option and choose \u2018Enable #include Diagnostics\u2019.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"1\"><span data-contrast=\"none\">#include References<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335559738&quot;:240,&quot;335559739&quot;:0}\">\u00a0<\/span><\/h3>\n<p>T<span data-contrast=\"auto\">he feature in Visual Studio allows you to analyze the usage of #include directives in your code. It shows where and how often each directive is referenced, which can be particularly useful when dealing with a long list of directives. If you find an #include directive that is infrequently used but significantly impacts your compile time, this tool will help you identify it quickly so you can take the necessary steps to optimize your code.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Once you enable #include diagnostics, you should see a line of text above each #include directive. This is the CodeLens feature in action. The text above the #include directive indicates the count of its references in your current file. Clicking this count opens a window listing these references. Selecting any reference from this list will direct you to its corresponding line of code in your project.<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_references.gif\"><img decoding=\"async\" class=\"aligncenter wp-image-33443 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_references.gif\" alt=\"An image illustrating references in #include diagnostics.\" width=\"828\" height=\"535\" \/><\/a><\/p>\n<h3><span data-contrast=\"none\">#include Build Time<\/span><\/h3>\n<p>T<span data-contrast=\"auto\">his feature presents the build time for each #include directive. To activate this, you\u2019ll need to run <\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/build-insights-now-available-in-visual-studio-2022\/\"><span data-contrast=\"none\">Build Insights<\/span><\/a><span data-contrast=\"auto\"> by navigating to <\/span><b><span data-contrast=\"auto\">Build <\/span><\/b><span data-contrast=\"auto\">-&gt; <\/span><b><span data-contrast=\"auto\">Run Build Insights. <\/span><\/b><span data-contrast=\"auto\">This action will generate the necessary build time data. <\/span><span data-contrast=\"auto\">This allows you to easily visualize and evaluate the build time for each #include directive by comparing its usage and compilation time. The information provided by #include Diagnostics can be utilized to optimize your #include directives and improve compilation time. In addition to the information provided by the new #include diagnostics you may also want to consider checking out our documentation on <\/span><a href=\"https:\/\/learn.microsoft.com\/en-us\/cpp\/cpp\/modules-cpp?view=msvc-170\"><span data-contrast=\"none\">C++ modules<\/span><\/a><span data-contrast=\"auto\"> as an alternative to #include to further improve compilation time.<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_buildTime-1.gif\"><img decoding=\"async\" class=\"aligncenter wp-image-33445 size-full\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/01\/include_diagnostics_buildTime-1.gif\" alt=\"A GIF displaying the #include build time using #include diagnostics.\" width=\"828\" height=\"333\" \/><\/a><\/p>\n<h3><span data-ccp-props=\"{}\">Send us your feedback\u00a0<\/span><\/h3>\n<p><span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\" data-contrast=\"auto\">Your feedback is invaluable to us as we strive to enhance your experience. Please feel free to leave your comments below. Alternatively, you can share your thoughts through the <\/span><a style=\"background-color: #f7f7f9; font-size: 1rem; text-align: var(--bs-body-text-align);\" href=\"https:\/\/developercommunity.visualstudio.com\/cpp\"><span data-contrast=\"none\">Visual Studio Developer Community<\/span><\/a><span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\" data-contrast=\"auto\">. We\u2019re also available on Twitter (<\/span><a style=\"background-color: #f7f7f9; font-size: 1rem; text-align: var(--bs-body-text-align);\" href=\"https:\/\/twitter.com\/visualc\"><span data-contrast=\"none\">@VisualC<\/span><\/a><span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\" data-contrast=\"auto\">) and can be reached via email at visualcpp@microsoft.com. We look forward to hearing from you!<\/span><span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\" data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re excited to announce that the #include Diagnostics feature is now available in Visual Studio 2022 17.9 Preview 2. This new feature allows you to better understand the behavior of #include directives by providing detailed information on each directive\u2019s references and build time.\u00a0 To begin utilizing this feature, activate #include diagnostics by performing a right-click [&hellip;]<\/p>\n","protected":false},"author":96741,"featured_media":33440,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33437","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>We\u2019re excited to announce that the #include Diagnostics feature is now available in Visual Studio 2022 17.9 Preview 2. This new feature allows you to better understand the behavior of #include directives by providing detailed information on each directive\u2019s references and build time.\u00a0 To begin utilizing this feature, activate #include diagnostics by performing a right-click [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/33437","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\/96741"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=33437"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/33437\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/33440"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=33437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=33437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=33437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}