2017-06-01 58 views
0

我試圖在這裏按照指示:https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc簡單dotnetcore應用在VS代碼沒有運行

我所做的:

mkdir todoapi 
cd todoapi 
dotnet new webapi 

當我在VS代碼打開Startup.cs,我沒有得到任何警告消息詢問我以下內容:

Select Yes to the Warn message "Required assets to build and debug are missing from 'TodoApi'. Add them?" 
Select Restore to the Info message "There are unresolved dependencies". 

我的本地設置有什麼問題?

我只想從withi VS代碼運行該程序。

如果我在調試模式下運行我得到這個錯誤:

The preLaunchTask 'build' terminated with exit code 1. 

在PowerShell中終端的命令「DOTNET」也不管用。應該是?

更新

我重新開始VS代碼,現在它拿起在終端的命令:當我運行我得到這個 DOTNET

現在:

launch: launch.json must be configured. Change 'program' to the path to the executable file that you would like to debug.

我推出.json有:

"configurations": [ 

     { 
      "name": ".NET Core Launch (console)", 
      "type": "coreclr", 
      "request": "launch", 
      "preLaunchTask": "build", 
      "program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>", 
      "args": [], 
      "cwd": "${workspaceRoot}", 
      "stopAtEntry": false, 
      "console": "internalConsole" 
     }, 
     { 
      "name": ".NET Core Launch (web)", 
      "type": "coreclr", 
      "request": "launch", 
      "preLaunchTask": "build", 
      "program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>", 
      "args": [], 
      "cwd": "${workspaceRoot}", 
      "stopAtEntry": false, 
      "launchBrowser": { 
       "enabled": true, 
       "args": "${auto-detect-url}", 
       "windows": { 
        "command": "cmd.exe", 
        "args": "/C start ${auto-detect-url}" 
       }, 
       "osx": { 
        "command": "open" 
       }, 
       "linux": { 
        "command": "xdg-open" 
       } 
      }, 
      "env": { 
       "ASPNETCORE_ENVIRONMENT": "Development" 
      }, 
      "sourceFileMap": { 
       "/Views": "${workspaceRoot}/Views" 
      } 
     }, 
+0

既然你提到了PowerShell,我猜你是在Windows上。如果你說'dotnet --version'在PowerShell上不起作用,那麼你可能需要重新安裝.net core cli。對我而言,當我在PowerShell或命令提示符中輸入時,'dotnet --version'可以正常工作。 – kimbaudi

回答

1

嘗試:

dotnet restore  //restore dependencies 
dotnet build  //build project 
dotnet run   //run project 
+0

這有效,但不在VS代碼。我想使用vs代碼編輯器,而不是命令行。 –

+0

您可以通過按Ctrl +〜來執行此操作,並運行上述命令,它將打開VS代碼中的chrome調試器。 –