2

How I do to work with non-Core Asp.Net MVC projects on Visual Studio Code?

I'm tired of slowness of Visual Studio Community, so I was thinking about if I can setup an VS Code environment for that.

2 Answers 2

5

Here is how I was able to do it for my projects:

  • Install Visual Studio Code (obviously)
  • Install C# plug-in (I hope you are using C#) - main benefit here is intellisense, syntax highlighting, some refactoring options
  • Make sure you have msbuild in your environment path for building solutions

Now the basic flow looks like this:

  1. Open Visual Studio Code
  2. Choose File -> Open Folder... menu option and open the folder that contains your asp.net mvc solution
  3. CTRL+SHIFT+P to run VS code command and find "OmniSharp: Select Project"
  4. Choose your solution
  5. Wait for OmniSharp to load (you can inspect its output by bringing up output view CTRL+j, select Output, 'OmniSharp Logs')

At this point you should be able to Go to any type with CTRL+T and typing the type name. Use CTRL+P to find files and edit them. And to build press CTRL+SHIFT+B. If you don't have vscode task configured for building, I believe VS Code will build a scaffold file for you which you need to fill out and then msbuild can be invoked to build your solution. Check mine out (put this in .vscode directory, in a file called tasks.json):

    {
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "msbuild",
    "args": [
        // Ask msbuild to generate full paths for file names.
        "/property:GenerateFullPaths=true",
        // "/p:Configuration=Release",
        "YOUR SOLUTION FILENAME.sln"
    ],
    "taskSelector": "/t:",
    "showOutput": "silent",
    "tasks": [
        {
            "taskName": "build",
            // 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"
        }
    ]
}

It will take some time to get used to but once you are there, it's awesome. No more VS.NET memory hogging and overall slowness.

I love it how fast the editor starts and closes. Just get used to the flow of open folder, CTRL+T or CTRL+P for navigating between classes/code files. And be patient with OmniSharp (C# plugin) as at times it becomes nonresponsive and syntax highlighting becomes unavailable. At that point, I just restart OmniSharp (via a CTRL+SHFT+P, find OmniSharp, restart option).

Biggest things I miss: debugging. VS Code with C# plugin only supports .NET Core debugging as far as I know. The way I get around this is usually having unit tests and then isolating the code I want to debug via a unit test and just iterate on the test until the problem is solved. In rare cases where I absolutely need a debugger, I just power up the good ol' Visual Studio beast, do debugging and get out.

Hope this helps!

4
  • May i know still the debugging only supports .Net core alone? Jul 24, 2020 at 12:14
  • That's correct, you can debug only .net core and not .net projects. Jul 25, 2020 at 13:05
  • Also i would like to know about debugging the nunit test in visual studio code. I could able to run the test by dotnet test command. But i could not able to debug the test. Jul 27, 2020 at 14:28
  • You might need to make sure you have referenced a few extra packages to run/debug .net core nunit tests from visual studio code. This article should give you good pointers: blog.thecodewhisperer.com/permalink/… Especially the part "Run Tests With NUnit" Jul 28, 2020 at 15:17
1

I've successfully setup my Visual Studio 2015+ ASP.NET project on VSCode.

I've created an gulpfile that handle the build for me:

  1. It starts an IISExpress instance.
  2. Refresh my browser on razor code change.
  3. And automatically rebuild my application when I change C# code.

You can find the gulpfile on my project's Github

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.