简体   繁体   中英

How to attach debugger for ASP.NET Core web site running in IIS targeting net47?

I just converted a large legacy site to Net Core. Because of some old code, I have to target net47 instead of netcoreapp2.0 / netstandard2.0.

Problem is that when I run the site in IIS, it starts up correctly, but then I cannot attach the debugger. The process list (Debug | Attach to process) does not show the dotnet.exe process at all.

To investigate this:

  • I created a new ASP.NET Core web application in Visual Studio 2017 targeting netcoreapp2.0,
  • published it (dotnet publish) and
  • pointed my IIS web site to the published directory.

After hitting the site, I was able to attach to the dotnet.exe process ok. Here is the .csproj file:

 <Project Sdk="Microsoft.NET.Sdk.Web"> <!-- dotnet.exe shows up in process list in Visual Studio 2017 --> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" /> </ItemGroup> </Project> 

I then retargeted it to net47 because that is what my site uses.

  • Because Microsoft.AspNetCore.All does not support net47, I replaced it with enough individual packages to make the site compile.
  • Published it (dotnet publish -f net47).
  • Pointed the IIS site to the new net47 published directory.

I could load the site ok and navigate around. However, dotnet.exe no longer appeared in the process list.

 <Project Sdk="Microsoft.NET.Sdk.Web"> <!-- dotnet.exe does NOT show up in process list in Visual Studio 2017 --> <PropertyGroup> <TargetFramework>net47</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.*" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.*" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.*" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.*" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.*" /> <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.*" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" /> </ItemGroup> </Project> 

Is there any way I can debug a site running in IIS that targets the Net Framework?

It's my experience that you must attach to the process name that matches your web application's executable; the default value is the project name.

Does w3wp.exe appear? If so, see if selecting that for debugging works. If it's targeting 47 and running in IIS, it may be using IIS's w3wp process.

This is a guess given what I saw; not in a position to verify at the moment. Let me know if it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM