简体   繁体   中英

Visual Studio 2017 dotnet crash when changing target build

At the moment I am building application in C#, in Visual Studio 2017. I need to change target build from "AnyPC" to "x86"(to be able to call some unmanaged dlls which are written in C). But when I am just changing target build in Configuration Manager(or in Properties)->switch to x86 platform/target; And after this I run the application,dotnet is crashing and error appears:"dotnet has stopped working".

I think I need somehow to use dotnet-x86 when compiling for x86 target, and to use dotnet(x64) when compiling for x64,somehow to add their paths but I have no idea how to do that. I hope you can help me guys

PS:I am working on Windows 10 x64, VS-2017 Community, using .NET core 2.0

my program:

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

Output from Debug:'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\2.0.6\\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The program '[7276] dotnet.exe' has exited with code 255 (0xff).

Or with disabled "Just My Code":'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\2.0.6\\System.Private.CoreLib.dll'. Cannot find or open the PDB file. The program '[1764] dotnet.exe' has exited with code 255 (0xff).

image of application

Thankfully I found the right answer for my problem: https://github.com/dotnet/cli/issues/7532


The .NET Core CLI team mentioned the fix is as follows:

Install both the x86 and x64 .NET Core 2.0 SDKs from https://www.microsoft.com/net/download/core . Put the following in a file named Directory.Build.targets that is somewhere above your project file (eg the root of the source repository). MSBuild will pick it up automatically for all projects:

<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>

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