2017-08-12 59 views
1

據我所知,我遵循了在Windows 10上的Visual Studio代碼中構建C++程序的所有步驟。我在C:/MinGW下安裝了gcc-7.1.0-64,在VS代碼中安裝了C/C++擴展,併爲我的HelloWorld.cpp配置了構建任務。在Visual Studio代碼中構建一個C++程序代碼

問題:

當我嘗試打開命令面板,然後鍵入Tasks: Run Build Task籌建方案,它顯示錯誤:

No Build Task found. Press 'Configure Build Task' to define one.

儘管我有已經完成了。我可能錯過了一些簡單的東西,但沒有任何教程或文檔可以在任何地方找到解釋如何使這項工作。任何幫助表示讚賞。

HelloWorld.cpp

#include <iostream> 

using namespace std; 

int main() { 
    std::cout << "Hello world\n"; 
} 

c_cpp_properties.json(無關的Mac/Linux安裝從片斷中省略)

{ 
    "configurations": [ 
     { 
      "name": "Win32", 
      "includePath": [ 
       "${workspaceRoot}", 
       "C:/MinGW/include/c++/7.1.0/*" 
      ], 
      "defines": [ 
       "_DEBUG", 
       "UNICODE" 
      ], 
      "intelliSenseMode": "msvc-x64", 
      "browse": { 
       "path": [ 
        "${workspaceRoot}", 
        "C:/MinGW/include/c++/7.1.0/*" 
       ], 
       "limitSymbolsToIncludedHeaders": true, 
       "databaseFilename": "" 
      } 
     } 
    ], 
    "version": 2 
} 

tasks.json

{ 
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "2.0.0", 
    "tasks": [ 
    { 
     "taskName": "HelloWorld.cpp", 
     "command": "c++", 
     "args": ["-g", "HelloWorld.cpp"], 
     "type": "shell" 
    } 
    ] 
} 

回答

1

感謝@ RobLourens對答案的評論。

The easiest way for tasks 2.0 is, run "Configure default build task", which will let you pick the build command, and set the group property for you.

我很快意識到,它增加了下指定的生成任務的"group"截面的線在tasks.json:(可以手動添加到規避正式方法

"isDefault": true, 
1

只需在您的任務內添加"isBuildCommand": true

+0

智能感知抱怨說:該屬性isBuildCommand已棄用。改用組屬性。另見1.14發行說明.' – ifconfig

+1

這是來自舊任務格式的屬性。任務2.0最簡單的方法是運行「配置默認構建任務」,這將允許您選擇構建命令,併爲您設置組屬性。 –