Click Ok
Click Ok

Reputation: 8862

Using Visual Studio Code with non-Core Asp.Net MVC

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.

Upvotes: 2

Views: 3602

Answers (2)

Saint Play
Saint Play

Reputation: 1083

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

Upvotes: 1

Laimonas Simutis
Laimonas Simutis

Reputation: 66

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!

Upvotes: 5

Related Questions