1

I've been trying to play around with Visual Studio Code and am struggling to get up and running with a .NET Core MVC web app following the getting started guides.

I installed Visual Studio Code, .NET Core SDK, and the C# code extension, and created the project using the dotnet new mvc command. I made sure I followed the prompt to add missing assets required to build and debug.

At this point, the tutorials I've read say you can run the application with F5, and they get a template page appear in the browser. However, when I try to run it, it takes me to the Environment dropdown. If I select .NET Core, it takes me to a launch.json file.

I'm new to Visual Studio code, so I'm not sure how best to troubleshoot this, or if there's something I've missed or misunderstood.

3
  • Can you link the tutorial(s) you used? Commented Sep 13, 2019 at 9:42
  • what does your launch.json look like? Commented Sep 13, 2019 at 9:47
  • F5 = Debug in Visual Studio. I'm not even sure it's the same command in Visual Studio Code, but even if it is, it can also be remapped. Somewhere (in a menu, context menu, etc.) you should have something to let you "Debug". Try that; it might be just that F5 doesn't do it. Commented Sep 13, 2019 at 12:52

3 Answers 3

3

In order for Visual Studio Code to run and debug your projects, you must create a launch configuration for each project. (See: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations)

From the Debug menu choose "Add Configuration..." and choose ".NET Core" for the environment.

Your launch configuration (launch.json) for a .NET Core MVC project would look something like this:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/Your.Application.dll",
        "args": [],
        "cwd": "${workspaceFolder}",
        "stopAtEntry": false,
        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceFolder}/Views"
        }
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }]
}

Then you can run and debug your .NET Core MVC web application from Visual Studio Code!

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for the responses. Thanks for the feedback. I've since deleted the test projects, but when I opened the launch.json file, it had some entries, but it was very basic compared to the launch.json file above. For example, it was missing the env and other entries.

"env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },

I don't know why it hadn't generated this. I had tried deleting and re-creating the project using the dotnet new mvc command several times, and it was the same each time.

However, now that I have re-visit it a week later, when I run dotnet new mvc, it creates the application with the full launch.json, as seen above, and it runs first time.

Comments

0

run command "dotnet run" in your terminal

1 Comment

Answer needs supporting information Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.