{"id":27664,"date":"2021-02-26T15:00:27","date_gmt":"2021-02-26T15:00:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=27664"},"modified":"2021-02-26T12:19:38","modified_gmt":"2021-02-26T12:19:38","slug":"remote-debug-support-in-visual-studio-2019","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/remote-debug-support-in-visual-studio-2019\/","title":{"rendered":"Remote Debug Support in Visual Studio 2019"},"content":{"rendered":"<p>Visual Studio 2019 offers remote debug support for MSBuild and CMake projects targeting Windows and Linux. Thanks to remote debugging, the following scenarios and more are now possible:<\/p>\n<ul>\n<li>Debugging on your production machines with no development tools installed other than the remote debugger tools.<\/li>\n<li>Targeting developer environments that you do not use daily (i.e., less common operating systems or software configurations).<\/li>\n<li>Targeting environments where Visual Studio is unavailable (i.e., ARM64 machines, or unsupported operating system versions).<\/li>\n<\/ul>\n<p>To guarantee a seamless remote debugging experience for users, you need some additional dependencies to be copied to the target machine. Luckily, we do that for you and automatically deploy these dependencies alongside the built binaries from your project we deem as needed for debugging. In Windows scenarios specifically, we automatically deploy the Universal CRT library (debug only, as the release version ships with the Windows operating system) as well as VCRuntime libraries which are necessary to run and debug binaries in environments where these libraries are not available on the system.<\/p>\n<p>For step-by-step instructions of the various remote debug workflows, check out the following tutorials:<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/debugger\/remote-debugging-cpp?view=vs-2019\">Remote Debug a C++ Project &#8211; Visual Studio | Microsoft Docs<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/deploy-run-and-debug-your-linux-project?view=msvc-160#:~:text=%20Debug%20your%20Linux%20project%20%201%20Select,option%20if%20the%20local%20version%20of...%20More\">Deploy, run, and debug your Linux MSBuild C++ project in Visual Studio | Microsoft Docs<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/cmake-remote-debugging?view=msvc-160\">Tutorial: Debug a CMake project on a remote Windows machine | Microsoft Docs<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/configure-cmake-debugging-sessions?view=msvc-160\">Configure CMake debugging sessions in Visual Studio | Microsoft Docs<\/a><\/p>\n<p><strong>Note:<\/strong> Although with Visual Studio 2019 you can create MSBuild and CMake projects targeting Linux and Windows, CMake is encouraged for Linux development because the same project files can be used in both platforms.<\/p>\n<h2>User Customizability of Remote Deploy<\/h2>\n<p>Whether you are targeting Windows or Linux, or using MSBuild or CMake, Visual Studio offers you the flexibility to customize your deployment. We will cover some of these in the sub-sections below.<\/p>\n<h3>MSBuild Projects targeting Windows<\/h3>\n<p>You can deploy and debug MSBuild projects targeting a remote Windows machine very easily in Visual Studio 2019. In the Property Pages, within the <strong>Debugging <\/strong>tab, you will need to specify <strong>Remote Command<\/strong>, <strong>Working Directory<\/strong>, <strong>Remote Server Name<\/strong> and <strong>Deployment Directory<\/strong> properties as a minimum. If you want to deploy additional files, you will have to specify them in the <strong>Additional Files to Deploy<\/strong> property.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-27665\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/word-image.png\" alt=\"The &quot;Deploy Visual C++ Runtime Libraries&quot; option highlighted and set to Yes\" width=\"1176\" height=\"817\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/word-image.png 1176w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/word-image-300x208.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/word-image-1024x711.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/word-image-768x534.png 768w\" sizes=\"(max-width: 1176px) 100vw, 1176px\" \/><\/p>\n<p>Visual Studio 2019 allows you to specify both debug and release versions of the runtime libraries. To do so, you must set the <strong>Deploy Visual C++ Debug Runtime Libraries<\/strong> and <strong>Deploy Visual C++ Runtime Libraries<\/strong> properties to <strong>Yes<\/strong>.<\/p>\n<p>Once your configuration is set, Visual Studio will take care of deploying all the files (including the ucrt and vcruntime libraries needed) to your remote machine.<\/p>\n<h3>MSBuild Projects targeting Linux<\/h3>\n<p>When targeting Linux using MSBuild project, you can specify a different machine from your build machine (the default) to deploy to and debug on, as shown below:<\/p>\n<h3><img decoding=\"async\" class=\"alignnone wp-image-27666\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/graphical-user-interface-text-application-email.png\" alt=\"The Remote Debug Machine setting set with a username, port, and authentication method\" width=\"887\" height=\"624\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/graphical-user-interface-text-application-email.png 887w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/graphical-user-interface-text-application-email-300x211.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/02\/graphical-user-interface-text-application-email-768x540.png 768w\" sizes=\"(max-width: 887px) 100vw, 887px\" \/><\/h3>\n<p>By default, only the files necessary for the process to debug will be deployed to the remote debug machine. However, in some cases, you may want more control over your project&#8217;s deployment. In these cases, you can append the code MSBuild elements below to your .vcxproj file, making sure to specify the actual source and target paths you want:<\/p>\n<pre class=\"prettyprint\">&lt;ItemGroup&gt; \r\n   &lt;RemoteDeploy Include=\"__example.cpp\"&gt; \r\n&lt;!-- This is the source Linux machine, can be empty if DeploymentType is LocalRemote --&gt; \r\n      &lt;SourceMachine&gt;$(RemoteTarget)&lt;\/SourceMachine&gt; \r\n      &lt;TargetMachine&gt;$(RemoteDebuggingTarget)&lt;\/TargetMachine&gt; \r\n      &lt;SourcePath&gt;~\/example.cpp&lt;\/SourcePath&gt; \r\n      &lt;TargetPath&gt;~\/example.cpp&lt;\/TargetPath&gt; \r\n&lt;!-- DeploymentType can be LocalRemote, in which case SourceMachine will be empty and SourcePath is a local file on Windows --&gt; \r\n      &lt;DeploymentType&gt;RemoteRemote&lt;\/DeploymentType&gt; \r\n&lt;!-- Indicates whether the deployment contains executables --&gt; \r\n      &lt;Executable&gt;true&lt;\/Executable&gt; \r\n   &lt;\/RemoteDeploy&gt; \r\n&lt;\/ItemGroup&gt;<\/pre>\n<p>You can also specify additional source files in your solution that you want deployed if you: right-click on the source file in solution explorer &gt; select properties &gt; set the <strong>Content <\/strong>property to \u201cyes\u201d.<\/p>\n<h3>CMake Projects targeting Windows<\/h3>\n<p>Visual Studio 2019 has support for deploying CMake projects to a remote Windows machine and debugging them with the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/debugger\/remote-debugging-cpp?view=vs-2019\">Visual Studio remote tools.<\/a> You can specify the <strong>type <\/strong>and <strong>remoteMachineName <\/strong>properties within the launch.vs.json file.<\/p>\n<pre class=\"prettyprint\">\"configurations\": [ \r\n   { \r\n      \"type\": \"remoteWindows\", \r\n      \"project\": \"CMakeLists.txt\", \r\n      \"projectTarget\": \"CMakeProject.exe (CMakeProject\\\\CMakeProject.exe)\", \r\n      \"name\": \"CMakeProject.exe (CMakeProject\\\\CMakeProject.exe)\", \r\n      \"remoteMachineName\": \"[remote machine\u2019s IP address]: [remote machine\u2019s port number]\", \r\n      \"deployDebugRuntimeLibraries\": true, \r\n      \"deployRuntimeLibraries\": true, \r\n      \"deployDirectory\": \"~\/foo\", \r\n      \"disableDeploy\": true, \r\n   } \r\n]<\/pre>\n<p>Visual Studio 2019 allows you to specify both debug and release versions of the runtime libraries. To do so, you must set the <strong>deployDebugRuntimeLibraries<\/strong> and <strong>deployRuntimeLibraries<\/strong> properties to <strong>true<\/strong>.<\/p>\n<p>The contents of the project outputs will be deployed automatically to C:\\Windows Default Deploy Directory\\&lt;targetname&gt; in the remote machine. If you want to specify a different location, you can set it up in the <strong>deployDirectory <\/strong>property. If you do not want to deploy files at all, you can set <strong>disableDeploy <\/strong>to <strong>true<\/strong>.<\/p>\n<p>In addition, you can specify individual additional files or entire directories you want to deploy each time in case there are some external source\/content files you want to be deployed. To do this, you add the following block to your launch.vs.json (make sure you replace example.cpp\/exampleDirectory with the actual path to your file\/directory):<\/p>\n<pre class=\"prettyprint\">\"deploy\": [ \r\n   { \r\n      \"sourcePath\": \"~\/example.cpp\", \r\n      \"targetPath\": \"~\/test\/example.cpp\", \r\n   }, \r\n   { \r\n      \"sourcePath\": \"~\/exampleDirectory\", \r\n      \"targetPath\": \"~\/test\/exampleDirectory\", \r\n   }, \r\n]<\/pre>\n<h3>CMake Projects targeting Linux<\/h3>\n<p><span style=\"font-size: 12pt;\">When targeting Linux using CMake, you can specify a different machine from your build machine (the default) to deploy to and debug on. To do this, just set the remoteMachineName json filed to one of the established connections in the Connection Manager (IntelliSense will populate the list of all the available options).<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">You can also customize the deploy location on the target machine by setting the <strong>deployDirectory <\/strong>property in launch.vs.json to the intended directory.<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">In addition, if you want complete control over your deployment, you can append the following code block in your launch.vs.json file. For example:<\/span><\/p>\n<pre class=\"prettyprint\">\"deploy\": [ \r\n   { \r\n      \"sourceMachine\": \"127.0.0.1 (username=example1, port=22, authentication=Password)\", \r\n      \"targetMachine\": \"192.0.0.1 (username=example2, port=22, authentication=Password)\", \r\n      \"sourcePath\": \"~\/example.cpp\", \r\n      \"targetPath\": \"~\/example.cpp\", \r\n      \"executable\": \"false\" \r\n   } \r\n]<\/pre>\n<h2>Give us your feedback<\/h2>\n<p>Download\u00a0the latest <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 Preview<\/a> today and give it a try. We\u2019d love to hear from you to help us prioritize and build the right features for you. We can be reached via the comments below,\u00a0<a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Developer Community<\/a>, and Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>). The best way to file a bug or suggest a feature is via Developer Community.<\/p>\n<h2>Authors<\/h2>\n<p>Moyo Okeremi and Lisbeth Cardoso Guerra.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2019 offers remote debug support for MSBuild and CMake projects targeting Windows and Linux. Thanks to remote debugging, our customers can target a wider, more diverse range of scenarios. We offer the flexibility to customize your deployment and automatically copy any dependencies needed to the target machine.<\/p>\n","protected":false},"author":24915,"featured_media":27665,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266,279],"tags":[],"class_list":["post-27664","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","category-linux"],"acf":[],"blog_post_summary":"<p>Visual Studio 2019 offers remote debug support for MSBuild and CMake projects targeting Windows and Linux. Thanks to remote debugging, our customers can target a wider, more diverse range of scenarios. We offer the flexibility to customize your deployment and automatically copy any dependencies needed to the target machine.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/27664","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\/24915"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=27664"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/27664\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/27665"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=27664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=27664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=27664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}