Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用'&书信电报;平台目标>;x86</平台目标>';_C#_Visual Studio Code_.net Core - Fatal编程技术网

C# 如何使用'&书信电报;平台目标>;x86</平台目标>';

C# 如何使用'&书信电报;平台目标>;x86</平台目标>';,c#,visual-studio-code,.net-core,C#,Visual Studio Code,.net Core,我在Visual Studio代码中设置了一个基本的C#控制台应用程序,如下所示: dotnet new console dotnet restore 然后我像这样建造: dotnet build 然后运行: dotnet run 这一切都按预期进行。但是,如果将平台目标更改为x86,则在再次构建和运行应用程序时会出现以下错误: 未处理的异常:System.BadImageFormatException:无法加载文件或程序集“C:\temp\code\testx86\u 2\bin\Deb

我在Visual Studio代码中设置了一个基本的C#控制台应用程序,如下所示:

dotnet new console
dotnet restore
然后我像这样建造:

dotnet build
然后运行:

dotnet run
这一切都按预期进行。但是,如果将平台目标更改为
x86
,则在再次构建和运行应用程序时会出现以下错误:

未处理的异常:System.BadImageFormatException:无法加载文件或程序集“C:\temp\code\testx86\u 2\bin\Debug\netcoreapp2.0\testx86\u 2.dll”。试图加载格式不正确的程序

我的文件:

Program.cs:

using System;

namespace testx86_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}
在设置平台目标之前测试x86_2.csproj:


Exe
netcoreapp2.0
设置平台目标后的testx86_2.csproj:


Exe
netcoreapp2.0
x86
版本:

  • Visual Studio代码:1.13.1
  • Microsoft(R)针对.NET Core的生成引擎版本15.3.409.57025

很有趣。我能够重现这个
x86
是正确的PlatformTarget名字对象(如果您将
x86
替换为不匹配的
win-x86
之类的东西,您将得到正确名字对象的列表)。您是否在x64操作系统上运行?另外,您的控制台应用程序是否有解决方案文件?(
dotnet新sln——名称testx86_2&&dotnet sln添加testx86_2.csproj
将为您设置一个,并将您的csproj添加到其中)Microsoft没有花太多精力推广32位代码,它确实已经过时了。这里最基本的不幸无疑是您使用了错误的dotnet.exe,您需要它的32位版本。现在下载站点正在崩溃,所以我不知道他们是否有一个可用的,应该有一个适用于Windows的。@HansPassant您是对的-使用32位二进制文件来构建和运行项目是有效的。如果你愿意,请加上这个作为回答。
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

</Project>