VS Code 不为使用 net452 Framework 为 .NET Core 编译的项目加载 PDB
VS Code loads no PDB for project compiled for .NET Core with net452 Framework
我目前正在努力将现有的 .NET Framework 4.5.2 项目与新的 ASP.NET Core 项目集成。我使用 .NET Core SDK 1.1.1
构建
到目前为止我有一个简单的 ASP 脚手架,它 运行 并且能够加载我的旧项目 DLL 但我无法使用 VS Code 调试它,因为生成的 PDB 似乎被忽略。
这是 csproj(我删除了对旧项目的包引用,但问题仍然存在)
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
当我将 TargetFramework 更改为 netcoreapp1.1 时,会创建一个 DLL 而不是 EXE,并且可以进行调试。知道为什么吗?
这里是 dotnet --info
的输出
.NET Command Line Tools (1.0.1)
Product Information:
Version: 1.0.1
Commit SHA-1 hash: 005db40cd1
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk.0.1
更新: C# 扩展 1.9.0 支持 .NET Framework 调试。参见 https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.9.0
为此,将 "type" 设置为 clr
并确保您的项目生成可移植 PDB。参见 https://github.com/OmniSharp/omnisharp-vscode/wiki/Portable-PDBs
csproj
<PropertyGroup>
<DebugType>portable</DebugType>
</PropertyGroup>
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Framework Launch (console)",
"type": "clr",
"request": "launch",
"program": "${workspaceRoot}/bin/Debug/net461/sample.exe",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
原创
在 .NET Core 中,可执行项目会生成一个“.dll”文件。要启动它,您 运行 "dotnet.exe ./myapp.dll"。
在 .NET Framework 中,可执行项目会生成一个“.exe”文件。要启动它,您直接 运行 该文件:"myapp.exe".
在撰写本文时(2017 年 3 月),VS Code 仅支持调试 .NET Core 进程。您可以在此处跟踪调试 .NET Framework 的功能请求:https://github.com/OmniSharp/omnisharp-vscode/issues/813。同时,您将需要使用 Visual Studio 来调试 .NET Framework 进程。
我目前正在努力将现有的 .NET Framework 4.5.2 项目与新的 ASP.NET Core 项目集成。我使用 .NET Core SDK 1.1.1
构建到目前为止我有一个简单的 ASP 脚手架,它 运行 并且能够加载我的旧项目 DLL 但我无法使用 VS Code 调试它,因为生成的 PDB 似乎被忽略。
这是 csproj(我删除了对旧项目的包引用,但问题仍然存在)
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
当我将 TargetFramework 更改为 netcoreapp1.1 时,会创建一个 DLL 而不是 EXE,并且可以进行调试。知道为什么吗?
这里是 dotnet --info
的输出 .NET Command Line Tools (1.0.1)
Product Information:
Version: 1.0.1
Commit SHA-1 hash: 005db40cd1
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk.0.1
更新: C# 扩展 1.9.0 支持 .NET Framework 调试。参见 https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.9.0
为此,将 "type" 设置为 clr
并确保您的项目生成可移植 PDB。参见 https://github.com/OmniSharp/omnisharp-vscode/wiki/Portable-PDBs
csproj
<PropertyGroup>
<DebugType>portable</DebugType>
</PropertyGroup>
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Framework Launch (console)",
"type": "clr",
"request": "launch",
"program": "${workspaceRoot}/bin/Debug/net461/sample.exe",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
原创
在 .NET Core 中,可执行项目会生成一个“.dll”文件。要启动它,您 运行 "dotnet.exe ./myapp.dll"。
在 .NET Framework 中,可执行项目会生成一个“.exe”文件。要启动它,您直接 运行 该文件:"myapp.exe".
在撰写本文时(2017 年 3 月),VS Code 仅支持调试 .NET Core 进程。您可以在此处跟踪调试 .NET Framework 的功能请求:https://github.com/OmniSharp/omnisharp-vscode/issues/813。同时,您将需要使用 Visual Studio 来调试 .NET Framework 进程。