2017-02-17 163 views
5

我期待在vscode中運行asp.net mvc應用程序,但似乎我在google上發現的唯一頁面是asp.net核心,這不是我所期待的。有人可以通過一些步驟指導我,我安裝了一些插件,如c#和msbuild。嘗試運行後。它顯示以下錯誤:「無法啓動外部程序的MSBuild產卵的MSBuild ENOENT」如何在Visual Studio代碼編輯器中運行asp.net mvc 4.5?

+0

嘗試VS社區版,而不是(如果你不想支付VS)。可能會讓你自己頭痛不已。 VS代碼編輯器無意做你想做的事情。 – ADyson

+0

是的,我想是的。好的,謝謝你。 – hmota

回答

7

按VS代碼文檔,代碼VS不支持在桌面上運行在.NET Framework應用程序調試。 ASP.NET MVC應用程序(儘管支持ASP.NET Core)不會被VS Code識別。因此,VS Code是輕量級編輯文件的工具,他們建議使用Visual Studio Community。

+0

哦,好吧,我幫你。 – hmota

7

錯誤Failed to launch external program msbuild . spawn msbuild ENOENT發生是因爲vscode \ task runner找不到msbuild。

要在Visual Studio代碼編輯器中運行asp.net mvc 4.5,您需要安裝msbuild工具(我安裝了2017版)和IIS Express。

你可以使用vswhere檢查MSBuild的位置,在我的情況是C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe

在vscode執行命令Tasks: Configure Task Runner和編輯根據該文件的tasks.json的內容。

{ 
    "version": "0.1.0", 
    "taskSelector": "/t:", 
    "showOutput": "silent", 
    "tasks": [ 
     { 
      "taskName": "build", 
      "args": [ 
       // Ask msbuild to generate full paths for file names. 
       "/property:GenerateFullPaths=true" 
      ], 
      "windows": { 
       // change according your msbuild location 
       "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe" 
      }, 
      // Show the output window only if unrecognized errors occur. 
      "showOutput": "silent", 
      // Use the standard MS compiler pattern to detect errors, warnings and infos 
      "problemMatcher": "$msCompile" 
     }, 
     { 
      "suppressTaskName": true, 
      "taskName": "iisexpress", 
      "isShellCommand": true, 
      "windows": { 
       "command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe" 
      }, 
      "args": [ 
       // change according your project folder and desired port 
       "/path:${workspaceRoot}\\MyProjectFolder", 
       "/port:51714" 
      ], 
      // Show the iisexpress output always. 
      "showOutput": "always" 
     } 
    ] 
} 

你並不需要重新啓動在每一個變化你的IIS,你只需要構建應用程序CTRL+SHIFT+B

如果您不想停止IIS,請使用vscode命令Tasks: Terminate Running Task

參考文獻:

https://stackoverflow.com/a/42719644/5270073

https://docs.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line

10

我創建了一個gulpfile可處理構建對我來說:

  1. 它啓動的IISExpress實例。
  2. 刷新我的瀏覽器剃刀代碼更改。
  3. 當我更改C#代碼時,自動重建我的應用程序。

您可以找到gulpfileproject's Github

相關問題