TekOnline

How to Run Your ASP.NET MVC App from VS Code by Pressing F5 (Yes, Even the Old .NET Framework Ones)

I spend most of my day in Visual Studio Code. It is fast, it is light, and it does not chew through 6GB of RAM just sitting there. But there is one thing that always tripped me up — getting an older ASP.NET MVC project running with a single keystroke. Pressing F5 in VS Code for a .NET Framework app is not quite the “just works” experience you get with .NET Core. But it is absolutely doable, and once it is set up, you will forget you ever needed the full Visual Studio IDE for day-to-day dev work.

This guide covers the exact steps. No fluff. Just the config that gets your app launching under IIS Express from VS Code, with debugging, on F5.


What You Are Up Against

.NET Core apps are self-contained executables. VS Code can launch them directly with the debugger attached. Easy.

.NET Framework ASP.NET MVC apps are different. They run under IIS or IIS Express. There is no single .exe you point a debugger at. You need VS Code to start IIS Express, point it at your project folder, attach the .NET Framework debugger, and launch the browser. That is four things that need to happen in sequence, and they all need to be wired up in two JSON files.

The good news: once the config is written, it just works.


Prerequisites

Before you touch any config, make sure you have these installed:

VS Code Extensions

  1. C# Dev Kit (by Microsoft) — This bundles the C# language server, solution explorer, and the .NET Framework debugger. You can use the older “C#” extension (OmniSharp) instead, but the Dev Kit is where Microsoft is putting their effort now.
  2. IIS Express (optional but recommended) — Installed as part of Visual Studio, or you can grab it from the IIS Express download page. VS Code does not ship with it, so you need it on your machine already.

System Requirements

  • Windows (IIS Express is Windows-only)
  • .NET Framework 4.x (whatever your project targets)
  • IIS Express installed (check C:\Program Files\IIS Express\iisexpress.exe)

Step 1: Open Your Project Folder

Open VS Code and drag in your solution folder — the one containing your .sln file. The C# Dev Kit will detect the solution and ask if you want to add debug assets. If it does not prompt you, you can trigger it manually.


Step 2: Generate the Debug Config

Open the Command Palette (Ctrl+Shift+P) and run:

.NET: Generate Assets for Build and Debug

This creates a .vscode folder with three files:

.vscode/
  launch.json
  tasks.json
  settings.json

If the command does not appear, you can create the files yourself. Do not worry — the manual config is not scary.


Step 3: The launch.json — Wire Up F5

Here is the launch.json that works for a standard ASP.NET MVC project. Create or replace .vscode/launch.json with this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "IIS Express (F5)",
            "type": "iis",
            "request": "launch",
            "preLaunchTask": "build",
            "iisConfig": {
                "appPool": "Clr4IntegratedAppPool",
                "iisWebSite": "Default Web Site",
                "applicationPath": "/",
                "physicalPath": "${workspaceFolder}"
            },
            "trace": false,
            "browser": "edge"
        }
    ]
}

What each setting does:

SettingWhat It Does
"type": "iis"Tells VS Code to launch IIS Express and attach the .NET Framework debugger to the w3wp.exe worker process.
"request": "launch"Launch a new instance of IIS Express (as opposed to attach to an already-running one).
"preLaunchTask": "build"Run the build task before launching. This must match a task name in tasks.json (next step).
"appPool"The IIS application pool. Clr4IntegratedAppPool is .NET 4.x. Use Clr2IntegratedAppPool if your project is that old.
"iisWebSite"The IIS Express site name. "Default Web Site" is the one that ships with IIS Express. If you have a custom site configured in applicationhost.config, use that name instead.
"applicationPath"The virtual path under the site. "/" means the root.
"physicalPath"The folder IIS Express serves. "${workspaceFolder}" points to your solution root. If your .csproj is in a subfolder like ./MyApp, set this to "${workspaceFolder}/MyApp".
"browser"Which browser to launch. Options: "chrome""edge""firefox", or null to skip.

If “iis” type is not recognised

Some older versions of the C# extension use "type": "clr" with an executable path instead. Here is the alternative config if the above does not work:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "IIS Express (legacy)",
            "type": "clr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "C:\\Program Files\\IIS Express\\iisexpress.exe",
            "args": [
                "/path:${workspaceFolder}",
                "/port:52845"
            ],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        }
    ]
}

This launches iisexpress.exe directly. The debugger will attach to the worker process spawned by IIS Express. The downside is you need to know (and hardcode) the port.


Step 4: The tasks.json — Build Before You Launch

If you used the “Generate Assets” command, VS Code creates a build task for you. If not, create .vscode/tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}",
                "/p:GenerateFullPaths=true",
                "/p:DebugType=full"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Wait — can I use dotnet build on a .NET Framework project?

Yes, if you have the .NET SDK installed and your project uses the SDK-style .csproj format. Many older projects still use the legacy format, which does not work with dotnet build.

If your project is legacy-format (no SDK-style .csproj), use MSBuild directly:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "msbuild",
            "type": "process",
            "args": [
                "${workspaceFolder}\\MySolution.sln",
                "/p:Configuration=Debug",
                "/p:Platform=\"Any CPU\"",
                "/p:GenerateFullPaths=true",
                "/p:DebugType=full",
                "/m"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Replace MySolution.sln with your actual solution file name. You can find it with:

dir *.sln

Also, make sure msbuild is on your PATH. It usually lives at:

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe

If it is not found, you can add a full path to the "command" field, or add it to your system PATH.


Step 5: Press F5

That is it. Press F5.

What happens:

  1. VS Code runs the build task from tasks.json. If it compiles, green checkmark.
  2. VS Code launches IIS Express, pointing it at your project folder.
  3. VS Code attaches the .NET Framework debugger to the IIS worker process (w3wp.exe).
  4. Your default browser opens to http://localhost:52845/ (or whatever port IIS Express picked).

Set a breakpoint, hit a page, and you are debugging.


Troubleshooting

“The program ‘[PID] w3wp.exe’ has exited with code 0”

IIS Express started but the worker process exited. Usually means the site failed to start. Check:

  • Your physicalPath actually contains a web.config and your compiled bin/ folder.
  • IIS Express is not already running on the same port. Kill it: taskkill /f /im iisexpress.exe

“Build failed” or “msbuild not found”

  • Open a Developer Command Prompt for VS and run where msbuild to find the path.
  • Use the full path in tasks.json"command": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"

Browser opens but nothing loads / 404

  • Check that IIS Express is serving from the right folder. Your physicalPath should point to the folder containing web.config.
  • If your project files are in a subdirectory (e.g. ./MozzieDB not ./), set "physicalPath": "${workspaceFolder}/MozzieDB".

Breakpoints are not hit (“No symbols loaded”)

  • Make sure you are building in Debug configuration (/p:Configuration=Debug in the build task).
  • Check your web.config has <compilation debug="true">.
  • Restart IIS Express, clean build, try again. The .NET Framework debugger can be stubborn.

Port conflicts

IIS Express picks a port from its applicationhost.config, usually at:

%USERPROFILE%\Documents\IISExpress\config\applicationhost.config

You can edit this file to set a fixed port. Search for your site name and change the <binding>.


Alternative: Skip IIS Express Entirely

If you are just doing frontend work (HTML, CSS, JS in your .cshtml files) and do not need the .NET backend running locally, you have simpler options:

Live Server Extension

Install the “Live Server” extension, right-click any .html or .cshtml file, and “Open with Live Server”. It will hot-reload on save. No debugging, no .NET, but instant feedback on markup and CSS changes.

The “just view it static” trick

Sometimes you just need to see if your layout looks right. Copy the rendered HTML from your browser (View Source), save it as a .html file, and open it directly. Crude. Effective. Not for production.


What We Learned

  1. VS Code can absolutely debug .NET Framework ASP.NET MVC apps. The setup takes 5 minutes, once, and then it is just F5 forever.
  2. Use the C# Dev Kit extension. It bundles the .NET Framework debugger and makes the IIS Express launch type available.
  3. The iis launch type is the cleanest option — one JSON block, no need to hardcode ports or call iisexpress.exe directly.
  4. Legacy .csproj projects need MSBuild, not dotnet build. If you see “project file not found” errors, this is why.
  5. Port management is the most common gotcha. IIS Express picks a random port from its config. If things do not load, check the port first.
  6. Set "preLaunchTask": "build" so you never forget to compile before hitting F5. Saves the “why is my change not showing up” moment.
  7. The physical path matters. Make sure it points to the folder with web.config and bin/, not the solution root if your project is nested.

One Last Thing

If you are committing this .vscode folder to git (and you should, so the whole team gets the same config), consider adding a .vscode/settings.json with project-specific overrides:

{
    "files.exclude": {
        "**/bin": true,
        "**/obj": true
    },
    "omnisharp.useModernNet": false
}

The useModernNet: false tells OmniSharp to use the legacy .NET Framework project loader instead of the SDK-style one. If you have a mix of old and new projects in the solution, leave it at true.


That is the setup. Five minutes of JSON editing, and you get F5 debugging back without launching the full Visual Studio IDE. Give it a go.


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *