如何在visual studio代码编辑器中运行asp.net mvc 4.5?

hmo*_*ota 17 asp.net-mvc visual-studio-code

我期待在vscode中运行asp.net mvc应用程序,但似乎我在google上找到的唯一页面是asp.net core,这不是我正在寻找的.有人可以指导我一些步骤,我安装了一些插件,如c#和msbuild.试图运行它之后.它显示以下错误:

"无法启动外部程序msbuild.spawn msbuild ENOENT"

Sai*_*lay 15

我已经为我创建了一个处理构建的gulp文件:

  1. 它启动一个IISExpress实例.
  2. razor代码更改时刷新我的浏览器.
  3. 当我更改C#代码时自动重建我的应用程序.

你可以在我的项目的Github上找到gulp文件


Ric*_*ana 11

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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

您无需在每次更改时重新启动IIS,只需构建应用程序即可CTRL+SHIFT+B.

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

参考文献:

/sf/answers/2990375111/

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


Ste*_*phy 10

根据VS Code文档,VS Code不支持调试Desktop .NET Framework上运行的应用程序.VS Code无法识别ASP.NET MVC应用程序(虽然支持ASP.NET Core).因此VS Code是编辑文件的轻量级工具,他们建议使用Visual Studio社区.


R00*_*007 5

对于 Visual Studio Code 1.30.2,我已将其配置为使用以下设置在 IISExpress 中构建和运行我的 ASP.NET 应用程序。

终端 -> 配置任务

然后选择Create tasks.json file from template entry

一旦你这样做,然后选择 MSBuild 模板

在此处输入图片说明

这将创建默认的 MS 构建任务模板。

您应该能够将以下内容复制到 task.json 文件中:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        //Task for building your ASP.NET Solution
        {
            "label": "build",
            "type": "shell",
            "command": "msbuild",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                "/t:build"
            ],
            "windows": {
                "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\msbuild.exe"
            },
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "always"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        },
        //Task for running App in IIS Express
        //You can add additional projects here if you want to run more than one project in IIS Express
        //For example this shows how I'm running my WebApp and API locally in IIS Expresse
        {
            "label": "iisexpress-WebApp",
            "type": "shell",
            "windows": {
                "command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
            },
            "args":[
                "/path:${workspaceRoot}\\Web",
                "/port:52945"
            ],
            "presentation": {
                "reveal": "always"
            }
        },
        {
            "label": "iisexpress-API",
            "type": "shell",
            "windows": {
                "command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
            },
            "args":[
                "/path:${workspaceRoot}\\Api",
                "/port:49243"
            ],
            "presentation": {
                "reveal": "always"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

保存文件后,只需按 Ctrl + Shift + B 并从窗口中选择 Build 任务。如果一切顺利,您应该会在下面的终端中看到输出。

在此处输入图片说明

然后要在 IIS 中启动您的应用程序,请转到终端 -> 运行任务

然后该窗口将显示您的 IIS Express 任务,选择您想要启动的任务,您应该会看到输出窗口显示 IIS 正在启动。一旦成功,只需打开浏览器并导航到 localhost:{portyouconfigured},您应该会看到您的应用程序正在运行。

在此处输入图片说明