debugging 如何使用Visual Studio 2022在Docker中调试x86. net7服务

xzabzqsa  于 12个月前  发布在  Docker
关注(0)|答案(1)|浏览(173)

bounty将在6天后到期。回答此问题有资格获得+200声望奖励。João Mendes希望引起更多关注此问题:我只是想要与当前架构兼容的东西......

我正在构建一个C#中间件服务,它必须调用32位COM DLL并调用SOAP Web服务。该服务是针对.NET7.0编写的,我使用的是Visual Studio 2022 Community Edition。
由于该DLL,该项目必须针对x86 Windows平台。
我想容器化这个服务。我安装了最新的Docker桌面,并在项目中添加了Docker支持。
当我点击Debug时,VS正确地创建了容器并下载了预期的图像,但是,一旦容器启动并运行,它就默默地退出了调试模式,并且没有输出到调试窗口或容器工具日志。
Dockerfile几乎是VS生成的默认文件:

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Trayport/Trayport.csproj", "Trayport/"]
RUN dotnet restore "Trayport/Trayport.csproj"
COPY . .
WORKDIR "/src/Trayport"
RUN dotnet build "Trayport.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Trayport.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Trayport.dll"]

下面是csproj:

<Project Sdk="Microsoft.NET.Sdk.Worker">
  <PropertyGroup>
    <TargetFramework>net7.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>dotnet-Trayport-69c0cd6b-2a27-4fa8-ab42-df4d743d63e3</UserSecretsId>
    <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
    <ServerGarbageCollection>true</ServerGarbageCollection>
    <Platforms>x86</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <COMReference Include="GV8APILib">
      <VersionMinor>0</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>0a67e301-3ecb-47be-bba9-dc67ff219358</Guid>
      <Lcid>0</Lcid>
      <WrapperTool>tlbimp</WrapperTool>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.10.*" />
    <PackageReference Include="System.ServiceModel.Federation" Version="4.10.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.10.*" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.10.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.10.*" />
  </ItemGroup>

  <ItemGroup>
    <None Update="Gv8Api.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="trayport-api-schema.xsd">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

从我在大量的谷歌搜索后收集到的信息来看,这似乎与VS docker构建在容器上部署和运行64位远程调试器的事实有关,但随后尝试附加到32位调试器。当它找不到调试器时,它就会停止,没有输出。
不过,问题可能完全出在别处...
如果相关的话,Docker Desktop和VS在同一台主机上运行,这是一台64位Windows 11 PC。

d7v8vwbk

d7v8vwbk1#

根据你的Dockerfile,我认为你有两个问题:
1.官方的.NET运行时镜像只有x64运行时。

  1. VS中的容器工具假定为x64,因此它们只设置x64调试器,并尝试启动x64运行时。
    第一个问题的快速修复方法是将x86运行时复制到现有镜像中。下面是一个更改Dockerfile的示例。
    你可以通过手动指定调试器使用ContainerVsDbgPath,并开始使用DockerDebuggeeProgram的程序来修复第二个问题。这里是这些属性的docs,以及设置它们以支持容器中的x86调试的示例。在制作示例时,我需要使用ServerCore作为我的基础映像来运行x86运行时,所以我可以使用完整的远程调试器。

相关问题