ערוך

שתף באמצעות


Debug .NET and ASP.NET Core source code with Visual Studio

To debug .NET and ASP.NET Core source code in Visual Studio:

  • In Tools -> Options -> Debugging -> General, un-check Enable Just My Code.

    Enable Just My Code

  • Verify Enable Source Link support is checked.

    Enable Source Link support

  • In Tool -> Options -> Debugging -> Symbols, enable Microsoft Symbol Servers.

    Microsoft Symbol Server

When you step into any .NET or ASP.NET Core code, Visual Studio displays the source code. For example:

  • Set a break point in OnGet in Pages/Privacy.cshtml.cs and select the Privacy link.

  • Select one of the Download Source and Continue Debugging options.

    Source Link Will Download

The preceding instructions work for basic stepping into functions, but the optimized .NET code often removes local variables and functions. To disable optimizations and allow better source debugging:

  • In Tools -> Options -> Debugging -> General, enable Suppress JIT optimization on module load (Managed only): Suppress JIT optimization on module load
  • Add the environment variable and value COMPlus_ReadyToRun=0 to the Properties/launchSettings.json file:
    {
      "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
          "applicationUrl": "http://localhost:10892",
          "sslPort": 44315
        }
      },
      "profiles": {
        "WebApplication18": {
          "commandName": "Project",
          "dotnetRunMessages": true,
          "launchBrowser": true,
          "applicationUrl": "https://localhost:7045;http://localhost:5045",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "COMPlus_ReadyToRun": "0"
          }
        },
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "COMPlus_ReadyToRun": "0"
          }
        }
      }
    }
    

If you have debugged an app before with the previous version of .NET, delete the %TEMP%/SymbolCache directory as it can have old PDBs that are out of date.

Debugging .NET Core on Unix over SSH

Additional resources