简体   繁体   中英

Build and run a windows .NET Core app on Debian (Exec format error)

I have this ASP.Net Core app which is written on a windows machine using latest Visual studio. Now I need to build and host this app on a Linux machine (Debian latest version).

Project .csproj looks like this:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Net.Compilers" Version="3.5.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Installed dotnet core 3.1 on my Linux using this link .

The output after running dotnet build is:

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... Restored /var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj (in 1.37 sec). /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error MSB3883: Unexpected exception: [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: System.ComponentModel.Win32Exception (8): Exec format error [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTermin al, Boolean throwOnNoExec) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.Start() [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at Mic rosoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj]

Build FAILED.

/root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error MSB3883: Unexpected exception: [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: System.ComponentModel.Win32Exception (8): Exec format error [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTermin al, Boolean throwOnNoExec) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at System.Diagnostics.Process.Start() [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] /root/.nuget/packages/microsoft.net.compilers/3.5.0/tools/Microsoft.CSharp.Core.targets(59,5): error: at Mic rosoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/var/lib/go-agent/pipelines/XXXXXX-pipeline/XXXXXX.DAL/XXXXXX.DAL.csproj] 0 Warning(s) 7 Error(s)

What is the problem?

Also dotnet --info output:

.NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment: OS Name: debian OS Version: 10 OS Platform: Linux RID: debian.10-x64 Base Path:
/usr/share/dotnet/sdk/3.1.301/

Host (useful for support): Version: 3.1.5 Commit: 65cd789777

.NET Core SDKs installed: 3.1.301 [/usr/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

lscpu output:

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 43 bits physical, 48 bits virtual CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 4 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family:
6 Model: 79 Model name: Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz Stepping: 1 CPU MHz:
2197.455 BogoMIPS: 4394.91 Hypervisor vendor: VMware Virtualization type: full L1d cache: 32K L1i cache:
32K L2 cache: 256K L3 cache: 30720K NUMA node0 CPU(s): 0-3 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt arat md_clear flush_l1d arch_capabilities

In my case the problem was mono package that needed to be installed. just install mono-complete package and the error might go away. I suggest following this link for installation as it helped me.

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