使用Visual C ++和Open Folder自定義環境
來源 https://blogs.msdn.microsoft.com/vcblog/2016/10/05/bring-your-c-codebase-to-visual-studio-with-open-folder/
Visual Studio 2017中稱為“ 打開文件夾 ” 的新功能完全支持C ++。 如果你有一個基於CMake的項目,請看一下這篇文章,描述我們的Visual Studio為CMake簡化的“開放文件夾”體驗。如果您的項目正在使用其他構建系統,請繼續閱讀。
安裝產品時,請確保安裝其中一個C ++工作負載,例如“使用C ++進行桌面開發”或“使用C ++進行游戲開發”。
之后,您只需運行“打開文件夾”命令並選擇要瀏覽的文件夾(從文件 > 打開 > 文件夾或快速啟動)或從命令提示符直接啟動devenv.exe <foldername>。
閱讀C ++代碼
打開文件夾后,解決方案資源管理器將立即顯示該文件夾中的文件,您可以在編輯器中打開任何文件。在后台,Visual Studio將開始索引文件夾中的C ++源代碼。
您現在可以訪問閱讀和瀏覽C ++代碼的所有Visual Studio功能(例如,查找所有引用,轉到符號,Peek定義,語義着色和突出顯示,類視圖,調用層次結構等等)。
編輯C ++代碼
所有這些C ++瀏覽和導航服務都可以工作,而無需像以前的Visual Studio版本那樣創建任何Visual C ++項目(通過“ 從現有代碼創建項目”向導)。
當您從項目中創建,重命名或刪除源文件時,您不必再擔心更新Visual C ++項目 - Visual Studio將依賴於文件夾結構並根據需要監視磁盤上的更改。此外,當您編輯代碼時,Visual Studio的IntelliSense將繼續更新並幫助您獲取源中的最新信息。
在編輯代碼時,您還可以使用Visual Studio支持C ++的所有重構功能,例如重命名符號,提取功能,移動定義位置,更改簽名,轉換為原始字符串文字等。
自定義C ++配置設置
默認情況下,VS將為IntelliSense和瀏覽提供兩種C ++配置:Debug和Release。這些配置與VS 2015中引入的單文件智能感知功能提供的配置一致。
根據項目的不同,您可能需要使用有關源代碼的更多信息來自定義這些配置,例如其他包含路徑,其他定義或編譯器開關。為此,在根文件夾中創建一個名為CppProperties.json的文件 - 該文件將有助於配置C ++ IntelliSense和瀏覽。
CppProperties.json:
|
1
2
3
4
五
6
7
8
9
10
11
12
13
|
{
"configurations"
: [
{
"name"
:
"Windows x64"
,
"includePath"
: [
"include"
],
"defines"
: [
"_DEBUG"
],
"compilerSwitches"
:
"/std:c++14"
,
"intelliSenseMode"
:
"msvc-x64"
,
"forcedInclude"
: [
"pch.h"
],
"undefines"
: []
}
]
}
|
以下屬性可用於給定配置:
- name:是將在C ++配置下拉列表中顯示的配置名稱
- includePath:應在include路徑中指定的文件夾列表(映射到/ I表示大多數編譯器)
- 定義:應定義的宏列表(映射到大多數編譯器的/ D)
- compilerSwitches:指定一個或多個可影響IntelliSense行為的附加開關
- forcedInclude:指定要自動包含在每個編譯單元中的標頭(映射到MSVC的/ FI或clang的-include)
- undefines:要定義的宏列表(映射到/ U表示MSVC)
- intelliSenseMode:指定要使用的IntelliSense引擎。您可以為MSVC或Clang指定體系結構特定的變體:
- msvc-x86(默認值)
- MSVC-64
- msvc -arm
- 窗戶 - 鐺 - 86
- 窗戶 - 鐺 - 64
- Windows的鐺臂
此文件支持包含路徑和其他屬性值的環境變量擴展。語法為$ {env.FOODIR}以擴展環境變量%FOODIR%。
您還可以訪問此文件中的內置宏:
- $ {workspaceRoot} - 提供工作空間文件夾的完整路徑
- $ {projectRoot} - 放置CppProperties.json的文件夾的完整路徑
- $ {vsInstallDir} - 安裝VS 2017運行實例的文件夾的完整路徑
例如,如果您的項目有一個包含文件夾,並且還包含Windows.h和Windows SDK中的朋友(這很常見),您可能希望使用以下內容更新配置文件:
CppProperties.json:
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
|
{
"configurations"
: [
{
"name"
:
"Windows"
,
"includePath"
: [
// local include folder
"${workspaceRoot}\\include"
,
// Windows SDK and CRT headers
"${env.WindowsSdkDir}include\\${env.WindowsSDKVersion}\\ucrt"
,
"${env.NETFXSDKDir}\\include\\um"
,
"${env.WindowsSdkDir}include\\${env.WindowsSDKVersion}\\um"
,
"${env.WindowsSdkDir}include\\${env.WindowsSDKVersion}\\shared"
,
"${env.VCToolsInstallDir}include"
]
}
]
}
|
注意:%WindowsSdkDir%和%VCToolsInstallDir%未設置為全局環境變量,因此請確保從定義這些變量的“VS 2017開發人員命令提示符”啟動devenv.exe。
提示:通常,錯誤列表窗口是查看由於缺少包含而導致的任何IntelliSense錯誤的良好起點 - 將其內容過濾為“僅限IntelliSense”,錯誤代碼為E1696:

您可以在CppProperties.json文件中創建任意數量的配置,並可以從標准工具欄中的C ++配置下拉列表輕松切換它們
CppProperties.json
|
1
2
3
4
五
6
7
8
9
10
11
12
|
{
"configurations"
: [
{
"name"
:
"Windows"
,
...
},
{
"name"
:
"with EXTERNAL_CODECS"
,
...
}
]
}
|
構建C ++項目
通過直接在IDE中將它們作為任務運行,您可以在當前工作空間中的文件上自動構建腳本或任何其他外部操作。您可以通過右鍵單擊文件或文件夾來配置新任務,然后選擇“ 自定義任務設置 ”。
這將在工作區中隱藏的.vs文件夾下創建一個新文件tasks.vs.json,以及一個可以自定義的新任務。
默認情況下,可以從解決方案資源管理器中的文件的上下文菜單執行任務。對於每個任務,您將在上下文菜單的底部找到一個新條目。
Tasks.vs.json
|
1
2
3
4
五
6
7
8
9
10
11
12
|
{
"version"
:
"0.2.1"
,
"tasks"
: [
{
"taskName"
:
"Echo filename"
,
"appliesTo"
:
"makefile"
,
"type"
:
"command"
,
"command"
:
"${env.COMSPEC}"
,
"args"
: [
"echo ${file}"
]
}
]
}
|
就像CppProperties.json一樣,在tasks.vs.json中,您可以使用語法$ {env.VARIABLE}來使用環境變量。
此外,您可以在任務屬性中使用內置宏:
- $ {workspaceRoot} - 提供工作空間文件夾的完整路徑(例如“C:\ sources \ hello”)
- $ {file} - 提供選擇運行此任務的文件或文件夾的完整路徑(例如“C:\ sources \ hello \ src \ hello.cpp”)
- $ {relativeFile} - 提供文件或文件夾的相對路徑(例如“src \ hello.cpp”)
- $ {fileBasename} - 提供沒有路徑或擴展名的文件名(例如“hello”)
- $ {fileDirname} - 提供文件的完整路徑,不包括文件名(例如“C:\ sources \ hello \ src”)
- $ {fileExtname} - 提供所選文件的擴展名(例如“.cpp”)
您還可以自己指定可在任務屬性中使用的其他用戶宏,例如下面示例中的$ {outDir}:
Tasks.vs.json
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
|
{
"version"
:
"0.2.1"
,
"outDir"
:
"${workspaceRoot}\\bin"
,
"tasks"
: [
{
"taskName"
:
"List outputs"
,
"appliesTo"
:
"*"
,
"type"
:
"command"
,
"command"
:
"${env.COMSPEC}"
,
"args"
: [
"dir ${outDir}"
]
}
]
}
|
通過將給定任務的“contextType”指定為“ build ”,“ clean ”或“ rebuild ”,您可以連接可以從上下文菜單調用的Build,Clean和Rebuild的VS內置命令。
Tasks.vs.json
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
{
"version"
:
"0.2.1"
,
"tasks"
: [
{
"taskName"
:
"makefile-build"
,
"appliesTo"
:
"makefile"
,
"type"
:
"command"
,
"contextType"
:
"build"
,
"command"
:
"nmake"
},
{
"taskName"
:
"makefile-clean"
,
"appliesTo"
:
"makefile"
,
"type"
:
"command"
,
"contextType"
:
"clean"
,
"command"
:
"nmake"
,
"args"
: [
"clean"
]
}
]
}
|
您可以通過在“applyTo”字段中指定其名稱來為任何文件或文件夾創建任務。但是要創建更多通用任務,您可以使用文件掩碼。例如:
- “applyTo”:“*” - 任務可用於工作區中的所有文件和文件夾
- “applyTo”:“* /” - 任務可用於工作區中的所有文件夾
- “applyTo”:“*。cpp” - 任務可用於工作空間中擴展名為.cpp的所有文件
- “applyTo”:“/ *。cpp” - 任務可用於工作空間根目錄中擴展名為.cpp的所有文件
- “applyTo”:“src / * /” - 任務可用於“src”文件夾的所有子文件夾
- “applyTo”:“makefile” - 任務可用於工作空間中的所有makefile文件
- “applyTo”:“/ makefile” - 任務僅在工作空間根目錄中的makefile上可用
調試C ++二進制文件
要在Visual Studio中開始調試,您需要在解決方案資源管理器中導航到可執行文件。然后右鍵單擊,選擇“ Debug ” - 這將立即啟動此可執行文件的調試會話。
或者,您可以在任務定義中指定輸出二進制文件(通過“輸出”)。一旦你這樣做,如果你選擇源文件作為啟動項(右鍵單擊,“ 設置為啟動項”)或只需右鍵單擊源文件並選擇“ 調試 ” ,這個二進制文件將在調試器下自動啟動。
Tasks.vs.json
|
1
2
3
4
五
6
7
8
9
10
11
12
13
|
{
"version"
:
"0.2.1"
,
"tasks"
: [
{
"taskName"
:
"makefile-build"
,
"appliesTo"
:
"makefile"
,
"type"
:
"command"
,
"contextType"
:
"build"
,
"command"
:
"nmake"
,
"output"
:
"${workspaceRoot}\\bin\\hellomake.exe"
}
]
}
|
如果要自定義程序的參數,請選擇“ 調試和啟動設置 ”。這將創建一個新的launch.vs.json文件,其中包含有關所選程序的信息。
要指定其他參數,只需將它們添加到“args”JSON數組中,如下例所示
launch.vs.json:
|
1
2
3
4
五
6
7
8
9
10
11
12
|
{
"version"
:
"0.2.1"
,
"defaults"
: {},
"configurations"
: [
{
"type"
:
"default"
,
"project"
:
"CPP\\7zip\\Bundles\\Alone\\O\\7za.exe"
,
"name"
:
"7za.exe list content of helloworld.zip"
,
"args"
: [
"l"
,
"d:\\sources\\helloworld.zip"
]
}
]
}
|
保存此文件后,“調試目標”下拉列表中的新條目將可用,您可以選擇它以啟動調試器。通過編輯launch.vs.json文件,您可以為任意數量的可執行文件創建任意數量的調試配置。如果現在按F5,調試器將啟動並命中您可能已設置的任何斷點。現在可以使用所有熟悉的調試器窗口和功能。
下一步是什么
立即下載Visual Studio 2017並嘗試“打開文件夾” - 不再需要創建VS項目和解決方案文件以在VS中提高工作效率。
我們正在繼續努力使這種體驗變得更好。在即將發布的版本中,您將看到我們增強了C ++瀏覽和導航的工作方式,並支持更多的調試器類型,最終與我們基於MSBuild的項目功能達到平等。您的反饋對於告知我們的后續步驟非常重要,所以請不要猶豫,分享。我們在聽!
使用Visual C ++和Open Folder自定義環境
來源 https://blogs.msdn.microsoft.com/vcblog/2017/11/02/customizing-your-environment-with-visual-c-and-open-folder/
自從我們發布了打開C ++代碼文件夾的支持以來,社區一直在要求對其構建和編輯環境進行更多控制。為此,我們在最新版本的Visual Studio 2017中添加了使用CppProperties.json自定義環境的新方法。
這個新的自定義表面使您可以使用更多種類的工具,編寫更簡潔的CppProperties文件,並具有類似於MSBuild的強大的每配置自定義。下面的主題擴展了原始C ++ Open Folder帖子中描述的幾個概念。如果您不熟悉編輯CppProperties.json,Launch.vs.json和Tasks.vs.json,則可能需要先閱讀該帖子。
這篇文章是我們之前關於為CMake項目定制環境的帖子的配套文件,所以如果您已經閱讀過,那么您可能會發現其中一些內容將是相似的,因為我們努力保持體驗的一致性。關於如何使用特定於配置的變量,最重要的區別在於“Launch.vs.json和Tasks.vs.json怎么樣”。
CppProperties.json中的新功能
這種新靈活性的核心在於項目的CppProperties.json文件,它來自兩個新概念:
- 能夠使用“inheritEnvironments”屬性全局或按配置繼承一組默認環境變量。
- 通過定義“環境”塊,可以全局或按配置定義自定義環境變量及其值。
將這些新概念與使用“$ {env.VAR}”語法在CppProperties.json,launch.vs.json和tasks.vs.json中使用環境變量的現有功能相結合,為創建豐富的開發環境提供了強大的機制。
讓我們從一個快速示例開始,說明如何使用此功能:
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
|
{
// The "environments" property is an array of key value pairs of the form
// { "EnvVar1": "Value1", "EnvVar2": "Value2" }
"environments"
: [
{
"INCLUDE"
:
"${workspaceRoot}\\src\\includes"
}
],
"configurations"
: [
{
"inheritEnvironments"
: [
// Inherit the MSVC 32-bit environment and toolchain.
"msvc_x86"
],
"name"
:
"x86"
,
"includePath"
: [
// Use the include path defined above.
"${env.INCLUDE}"
],
"defines"
: [
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x86"
},
{
"inheritEnvironments"
: [
// Inherit the MSVC 64-bit environment and toolchain.
"msvc_x64"
],
"name"
:
"x64"
,
"includePath"
: [
// Use the include path defined above.
"${env.INCLUDE}"
],
"defines"
: [
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x64"
}
]
}
|
為了解壓縮這個,這個例子定義了使用Microsoft的Visual C ++工具鏈構建的兩個配置。x86的第一個構建(因為它繼承了“msvc_x86”環境),而另一個構建了x64。它還定義了兩個配置使用的環境變量“INCLUDE”(第6行)。
請記住,可以為所有配置,每個配置或兩者全局定義“環境”(第4行)和“inheritEnvironments”(第12行和第25行)屬性。在上面的示例中,“INCLUDE”變量將是全局變量,“inheritEnvironment”屬性將僅適用於每個單獨的配置。
今天有以下環境:
- 使用MSVC(msvc_x86)定位x86 Windows
- 使用MSVC(msvc_x64)定位x64 Windows
- 使用64位MSVC(msvc_x64_x86)定位x86 Windows
- 使用64位MSVC(msvc_x64_x64)定位x64 Windows
此外,如果安裝了Linux Workload,則可以使用以下環境遠程定位 Linux和WSL:
- 遠程目標x86 Linux(linux_x86)
- 遠程定位x64 Linux(linux_x64)
- 遠程目標ARM Linux(linux_arm)
特定於配置的環境變量最后被評估,因此它們會覆蓋全局變量。以下示例說明了注釋中的覆蓋行為:
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
{
// The "environments" property is an array of key value pairs of the form
// { "EnvVar1": "Value1", "EnvVar2": "Value2" }
"environments"
: [
{
"INCLUDE"
:
"${workspaceRoot}\\src\\includes"
}
],
"configurations"
: [
{
"inheritEnvironments"
: [
// Inherit the MSVC 32-bit environment and toolchain.
"msvc_x86"
],
"name"
:
"x86"
,
"includePath"
: [
// Use the include path defined above.
"${env.INCLUDE}"
],
"defines"
: [
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x86"
},
{
// The "environments" property is an array of key value pairs of the form
// { "EnvVar1": "Value1", "EnvVar2": "Value2" }
"environments"
: [
{
// Append 64-bit specific include path to env.INCLUDE.
"INCLUDE"
:
"${env.INCLUDE};${workspaceRoot}\\src\\includes64"
}
],
"inheritEnvironments"
: [
// Inherit the MSVC 64-bit environment and toolchain.
"msvc_x64"
],
"name"
:
"x64"
,
"includePath"
: [
// Use the include path defined above.
"${env.INCLUDE}"
],
"defines"
: [
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x64"
}
]
}
|
如果需要為構建環境聲明大量變量,然后對每個配置僅對它們進行少量修改,則此覆蓋行為可能會大大壓縮項目的CppProperties.json文件。
那么Launch.vs.json和Tasks.vs.json呢
如果您想知道是否可以在CppProperties.json文件之外使用這些變量,答案是肯定的!您在CppProperties.json中聲明的所有環境變量也可以在launch.vs.json和tasks.vs.json中使用。只需將相同的“$ {env.VarName}”語法嵌入到任務或啟動配置中的任何屬性值中。宏語法將擴展為其實際值,如第16行所示。
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
{
"version"
:
"0.2.1"
,
"tasks"
: [
{
"taskName"
:
"build-helloworld"
,
"appliesTo"
:
"*.cpp"
,
"contextType"
:
"build"
,
"type"
:
"launch"
,
"command"
:
"${env.comspec}"
,
"workingDirectory"
:
"${workspaceRoot}"
,
// Use environment from selected configuration, you can omit this
// to only use globally defined variables instead.
"inheritEnvironments"
: [
"${cpp.activeConfiguration}"
],
"output"
:
"${workspaceRoot}\\bin\\helloworld.exe"
,
"args"
: [
"build.bat ${env.BUILD_ARGS}"
]
}
]
}
|
如果環境變量的值是特定於配置的,那么當您在任務或啟動配置中包含此任務時,將使用當您嘗試運行任務或調試程序時當前所選配置的值:
|
1
|
"inheritEnvironments"
: [
"${cpp.activeConfiguration}"
]
|
如果不包括此項,則只有全局定義的變量可用。
您聲明的環境變量也將由任務啟動的進程繼承。另一方面,正在調試的程序不會自動繼承構建環境。下面的示例顯示了如何將環境變量顯式傳遞給已啟動的進程。
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
{
"version"
:
"0.2.1"
,
"defaults"
: {},
"configurations"
: [
{
"type"
:
"native"
,
"name"
:
"helloworld.exe"
,
// Use environment from selected configuration, you can omit this
// to only use globally defined variables instead.
"inheritEnvironments"
: [
"${cpp.activeConfiguration}"
],
"project"
:
"bin\\helloworld.exe"
,
"args"
: [
// Use arguments defined in CppProperties.json.
"${env.PROG_ARGS}"
] ,
"env"
:
"var1=${env.var1}\u0000var2=hardcodedvalue"
}
]
}
|
您可以在第14行看到可以引用CppProperties.json文件中定義的變量。第17行的“\ u0000”是用於分隔變量的空字符。
高級功能
那些有敏銳眼光的人可能已經注意到“environment”和“inheritEnvironments”是CppProperties.json語法中的數組。可以從多個環境聲明和繼承。對於典型的構建方案,您不太可能希望從多個環境繼承,但在某些情況下您可能希望聲明多個環境塊。這個的主要用例是聲明一些可以在任何CppProperties,Launch或Tasks JSON中引用但不希望添加到構建環境本身的變量 - 例如,不會由生成的構建過程繼承。
以下示例顯示了如何完成創建自定義命名空間:
|
1
2
3
4
五
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
三十
31
32
33
34
35
36
37
38
|
{
// The "environments" property is an array of key value pairs of the form
// { "EnvVar1": "Value1", "EnvVar2": "Value2" }
"environments"
: [
{
"INCLUDE"
:
"${workspaceRoot}\\src\\includes"
},
{
// "namespace" is a reserved key that lets you put variables
// in namespaces other than $env.
"namespace"
:
"special"
,
// SpecialVar will not be added to the environment.
"SpecialVar"
:
"special"
}
],
"configurations"
: [
{
"inheritEnvironments"
: [
// Inherit the MSVC 32-bit environment and toolchain.
"msvc_x86"
],
"name"
:
"x86"
,
"includePath"
: [
// Use the include path defined above.
"${env.INCLUDE}"
],
"defines"
: [
// You can use alternative namespaces (such as special defined above)
// just like "${env.VAR}"
"${special.specialVar}"
,
"WIN32"
,
"_DEBUG"
,
"UNICODE"
,
"_UNICODE"
],
"intelliSenseMode"
:
"msvc-x86"
}
]
}
|
您可以使用語法“$ {special.SpecialVar}”在任何CppProperties,Launch或Tasks JSON文件中訪問“SpecialVar”,如第32行所示。
向我們發送反饋
要試用最新和最好的C ++功能並給我們一些早期反饋,請下載並安裝最新的 Visual Studio 2017 Preview。一如既往,我們歡迎您的反饋。您可以通過電子郵件發送電子郵件至visualcpp@microsoft.com,通過 Twitter @visualc或Microsoft Visual Cpp的 Facebook 發送任何評論。
如果您在使用Visual Studio 2017時遇到其他問題,請通過報告問題告訴我們 ,安裝程序和IDE本身都可以使用。有關建議,請通過UserVoice告知我們 。
Visual Studio中的遠程任務
來源 https://blogs.msdn.microsoft.com/vcblog/2017/10/23/remote-tasks-in-visual-studio/
We have introduced a new capability to run remote tasks in Visual Studio 2017 15.5 Preview 2. This capability allows you to run any command on a remote system that is defined in Visual Studio’s Connection Manager. Remote tasks also provide the capability to copy files to the remote system. This feature is added when you install the Linux development with C++ workload . If you want to learn more about the Open Folder capability in general read https://aka.ms/openfolder/cpp.
To get started with this create a file main.cpp in a folder on your PC, add the source below to it and open the folder in VS.
#include
int main()
{
std::cout << "Hello" << std::endl;
}
To get Linux IntelliSense for this file go to the menu Project > Edit Settings > CppProperties.json. Modify the file so it just has one entry like the below.
{
"configurations": [
{
"inheritEnvironments": [
"linux_x64"
],
"name": "Linux-x64",
"includePath": [
"${env.INCLUDE}"
],
"defines": [
]
}
]
}
In the Solution Explorer right click main.cpp and choose Configure Tasks. In the tasks.vs.json file that opens modify the task as follows. This task will copy the directory to the remote machine specified, then run “g++ main.cpp” in the directory specified.
{
"version": "0.2.1",
"tasks": [
{
"taskName": "Build",
"appliesTo": "main.cpp",
"type": "remote",
"contextType": "build",
"command": "g++ main.cpp",
"remoteMachineName": "ubuntu",
"remoteCopyDirectory": "~/sample",
"remoteCopyMethod": "sftp",
"remoteWorkingDirectory": "~/sample/hello",
"remoteCopySourcesOutputVerbosity": "Verbose"
}
]
}
You can run this task by right clicking main.cpp in the Solution Explorer and selecting Build. The Output window will show the file copy results. There is no output from this compile command, unless you have an error.
The field type is where we can change the context of the type to run on the remote machine, command is what will be executed there. The context type build places this command into that area of the context menu for the file the task applies to. The field remoteMachineName needs to match a defined connection in the Visual Studio Connection Manager. You can find that in the Quick Launch (Ctrl+Q) by typing Connection Manager, or under Tools > Options > Cross Platform > Connection Manager. Note that you can specify different directories for where to copy files vs where to run commands with the fields remoteCopyDirectoy and remoteWorkingDirectory. When the files are copied they are copied into a folder of the same name as the folder you have open in Visual Studio at the location specified. By default commands are executed in your home directory on the remote system. You can also specify the method you want to use for copying, sftp, rsync or none to disable. The rsync method is recommended for large projects. The remoteCopySourcesOutputVerbosity option is not necessary but is useful to know about if you are trying to diagnose an issue.
You can do anything you like with remote tasks of course. To run the output of our first command above, add another task after the one above.
{
"taskName": "Run",
"appliesTo": "main.cpp",
"type": "remote",
"command": "./a.out",
"remoteMachineName": "localhost",
"remoteWorkingDirectory": "~/sample/hello",
"remoteCopySourcesOutputVerbosity": "Verbose"
}
This task will show up as “Run” at the bottom of the context menu when you select main.cpp in the Solution Explorer. When executed, after you have compiled, you should see “Hello” in the output window.
What’s next
Download the Visual Studio 2017 Preview, install the Linux C++ Workload, and give it a try with your projects.
This is a very simple example of this new feature. We look forward to hearing about how you are using it in your projects.
The best way to reach us is via our GitHub hosted issue list, directly via mail at vcpplinux-support@microsoft.com or find me on Twitter @robotdad.
==================== End














