Getting F5 Working in VS Code with a Legacy ASP.NET MVC App

Pressing F5 in a modern .NET project usually builds and launches the app for you. A classic ASP.NET MVC application targeting .NET Framework is different: it commonly needs Visual Studio MSBuild, IIS Express, and a separate CLR attach step. You can still make the workflow predictable in Visual Studio Code.

This guide uses Windows, an existing MVC project, Visual Studio Build Tools, IIS Express, and the Microsoft C# extension. Adjust paths and the project name for your machine.

1. Check the prerequisites

  • Install the .NET Framework developer pack that matches the project target.
  • Install Visual Studio Build Tools with the .NET desktop build tools and MSBuild.
  • Install IIS Express and the Microsoft C# extension for VS Code.
  • Open the repository root in VS Code, so task paths such as ${workspaceFolder} resolve correctly.

For an older .csproj, the dotnet CLI may not build the project. Use the MSBuild executable installed with Visual Studio Build Tools and build the web project in Debug configuration.

2. Add build and IIS Express tasks

Create .vscode/tasks.json. A process task launches the executable directly; this makes the IIS Express process easier for VS Code to stop than launching it through an intermediate PowerShell shell.

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "type": "process",
      "command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe",
      "args": ["MozzieDB\\MozzieDB.csproj", "/p:Configuration=Debug"],
      "group": { "kind": "build", "isDefault": true },
      "problemMatcher": "$msCompile"
    },
    {
      "label": "start-iis",
      "type": "process",
      "command": "C:\\Program Files\\IIS Express\\iisexpress.exe",
      "args": ["/path:${workspaceFolder}\\MozzieDB", "/port:54932"],
      "isBackground": true,
      "problemMatcher": {
        "pattern": { "regexp": "^.*$", "file": 1, "location": 2, "message": 3 },
        "background": {
          "activeOnStart": true,
          "beginsPattern": "^Starting IIS Express",
          "endsPattern": "^IIS Express is running|Registration completed"
        }
      }
    },
    {
      "label": "build-and-run",
      "dependsOn": ["build", "start-iis"],
      "dependsOrder": "sequence"
    }
  ]
}

Change the MSBuild path, project path, site folder, and port to match your setup. The background problem matcher tells VS Code when IIS Express has finished starting, which lets the launch configuration continue. If your IIS Express version prints different startup messages, tune beginsPattern and endsPattern to match its output.

3. Use F5 to build, start the site, and open a browser

Add a browser launch configuration to .vscode/launch.json. This part of F5 runs the build and background server task, then opens the local site in Chrome:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch site in Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:54932",
      "webRoot": "${workspaceFolder}/MozzieDB",
      "preLaunchTask": "build-and-run"
    }
  ]
}

Select Launch site in Chrome in Run and Debug, then press F5. This launches the browser. It does not, by itself, attach the C# debugger to the ASP.NET worker process.

4. Attach for server-side C# breakpoints

Add another configuration for the Desktop CLR debugger. Start the site first, then select this configuration and press F5 to attach to IIS Express:

{
  "name": "Attach to IIS Express (.NET Framework)",
  "type": "clr",
  "request": "attach",
  "processName": "iisexpress",
  "justMyCode": false
}

On some machines, IIS Express starts more than one instance. Choose the process whose command line contains your site path or port if the debugger offers a process picker. For a full IIS deployment, attach to the correct w3wp.exe worker process instead.

5. If breakpoints stay hollow

  • Confirm the build succeeded in Debug and that the deployed DLL and PDB are from that same build.
  • Check the loaded module path matches the project you opened in VS Code.
  • Confirm IIS Express is running the app folder and port you expect.
  • Restart the app after rebuilding so IIS does not keep an older assembly loaded.
  • Check the C# extension output and debugger output for attach or symbol-loading errors.

The C# extension’s Desktop .NET Framework debugger has limitations: its documented support is for 64-bit applications with portable PDBs. Older projects may generate Windows PDBs or run as 32-bit. If the debugger cannot load symbols or attach, verify the project’s platform and symbol format; Visual Studio may be the better debugger for that legacy configuration.

Stopping the app cleanly

Use VS Code’s Stop action to end the debug session and stop the active task. If IIS Express is launched through a shell command and remains behind, change the task to "type": "process", with IIS Express as command and its switches in args. You can also check Task Manager or inspect the listener on the configured port when diagnosing a stale local server.

With the tasks separated this way, F5 has a clear job: compile the legacy project, wait for IIS Express, and bring up the site. A second attach configuration connects C# breakpoints to the running .NET Framework process.

Leave a Reply

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