更改目标版本时 Visual Studio 2017 dotnet 崩溃

Den*_*nis 6 .net c# x86 target visual-studio

目前,我正在 Visual Studio 2017 中使用 C# 构建应用程序。我需要将目标构建从“AnyPC”更改为“x86”(以便能够调用一些用 C 编写的非托管 dll)。但是当我只是在配置管理器(或属性)中更改目标构建时->切换到 x86 平台/目标;在此之后我运行应用程序,dotnet 崩溃并出现错误:“dotnet 已停止工作”。

我想我需要在编译 x86 目标时以某种方式使用 dotnet-x86,并在编译 x64 时使用 dotnet(x64),以某种方式添加它们的路径,但我不知道该怎么做。我希望你能帮助我伙计们

PS:我正在使用 .NET core 2.0 开发 Windows 10 x64、VS-2017 社区

我的程序:

 class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Need Help");
        Console.ReadKey();
    }
}
Run Code Online (Sandbox Code Playgroud)

调试的输出:'dotnet.exe'(CoreCLR:DefaultDomain):加载的'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.6\System.Private.CoreLib.dll'。跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。程序“[7276] dotnet.exe”已退出,代码为 255 (0xff)。

或者禁用“Just My Code”:'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.6\System.Private.CoreLib.dll' . 无法找到或打开 PDB 文件。程序“[1764] dotnet.exe”已退出,代码为 255 (0xff)。

应用程序图片

Den*_*nis 5

值得庆幸的是,我找到了问题的正确答案: https ://github.com/dotnet/cli/issues/7532


.NET Core CLI 团队提到的修复如下:

从https://www.microsoft.com/net/download/core安装 x86 和 x64 .NET Core 2.0 SDK 。将以下内容放入项目文件上方某个名为 Directory.Build.targets 的文件中(例如源存储库的根目录)。MSBuild 将为所有项目自动选择它:

<Project>
  <PropertyGroup 
      Condition="'$(OS)' == 'Windows_NT' and
                 '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
                 '$(SelfContained)' != 'true'"
                  >
    <RunCommand Condition="'$(PlatformTarget)' == 'x86'">$(MSBuildProgramFiles32)\dotnet\dotnet</RunCommand>
    <RunCommand Condition="'$(PlatformTarget)' == 'x64'">$(ProgramW6432)\dotnet\dotnet</RunCommand>
  </PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)