简体   繁体   English

Raspberry PI 上 Ubuntu 上的 ASP.NET Core 应用程序

[英]ASP.NET Core app on Ubuntu on Raspberry PI

I've installed Ubuntu Core 16.04 on a Raspberry PI 3 and managed to get a .NET Core console app running on it by using the instructions here and using .NET Core version 1.2.0-beta-001291-00 which is compatible with ARM chips.我已经在 Raspberry PI 3 上安装了 Ubuntu Core 16.04,并通过使用此处的说明并使用与 ARM 兼容的 .NET Core 版本 1.2.0-beta-001291-00 设法让 .NET Core 控制台应用程序在其上运行筹码。

When I do the same with a basic ASP.NET Core app I get the following error :当我对基本的 ASP.NET Core 应用程序执行相同操作时,出现以下错误:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Component.Primitives, Version=4.2.0.0, Cultire=Neutral, PublicKeyToken=b03f5f7f11d50a3a'.未处理的异常:System.IO.FileLoadException:无法加载文件或程序集“System.Component.Primitives,Version=4.2.0.0,Cultire=Neutral,PublicKeyToken=b03f5f7f11d50a3a”。 The located assembly's manifest definition does not match the assembly reference.定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) at Microsoft.Extensions.FileProviders.PhysicalFileError.CreateFileWatcher(String root) at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize>(IHostingEnvironment hostingEnvironment, String appplicationName, String contentRootPath, WebHostOptions options) at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Program.Main(String[] args) in /home/freek/aspnetcore/program.cs: line 12 Aborted (来自 HRESULT 的异常:0x80131040)在 Microsoft.Extensions.FileProviders.PhysicalFileError.CreateFileWatcher(String root) 在 Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize>(IHostingEnvironment hostingEnvironment, String appplicationName, StringOptionsRoot options, at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize> AspNetCore.Hosting.WebHostBuilder.BuildHostingServices() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Program.Main(String[] args) in /home/freek/aspnetcore/program.cs: line 12 Aborted

Here is the contents of program.cs :这是 program.cs 的内容:

using System;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

public class Program
{
  public static void Main(string[] args)
  {
    Console.WriteLine("Hello World API!");

    var builder = new ConfigurationBuilder()
      .SetBasePath(Directory.GetCurrentDirectory())
      .AddJsonFile("appsettings.json", optional: true)
      .Build();

    var host = new WebHostBuilder()
      .UseKestrel()
      .UseConfiguration(builder)
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseStartup<Startup>()
      .Build();

    host.Run();       
  }  
}

The code runs fine on a deskop with Ubuntu running .NET Core 1.1 but gives the error on a PI running .NET Core 1.2.0-beta-001291-00.该代码在运行 .NET Core 1.1 的 Ubuntu 桌面上运行良好,但在运行 .NET Core 1.2.0-beta-001291-00 的 PI 上出现错误。

Microsoft has been matching their version numbers for all of their core projects.微软一直在匹配他们所有核心项目的版本号。 Most package developers are following suit.大多数软件包开发人员都在效仿。 So .net core version 1.1.0 most packages that are compatible with that version are also version 1.1.0所以 .net core 版本 1.1.0 大多数与该版本兼容的软件包也是 1.1.0 版本

You need to update your project dependencies to their beta versions also.您还需要将项目依赖项更新为其 Beta 版本。 If you look at your project.json and go through all the dependencies look them up on nuget.org and get their latest beta version (1.2.0-beta-something) and update the project.json version number to the one you find on nuget.org it may work.如果您查看您的 project.json 并查看所有依赖项,请在 nuget.org 上查找它们并获取它们的最新测试版 (1.2.0-beta-something) 并将 project.json 版本号更新为您在其上找到的版本号nuget.org 它可能会工作。 It is beta after all.毕竟是测试版。

My recommendation would be to installed .net core 1.1.0 on the Raspberry Pi and then it should work fine.我的建议是在 Raspberry Pi 上安装 .net core 1.1.0,然后它应该可以正常工作。 However if you can't do that the above should work.但是,如果您不能这样做,则上述方法应该有效。

It is important to publish the solution with the correct Runtime Identifier (RID) .使用正确的运行时标识符 (RID)发布解决方案很重要。

For Raspberry Pi, you should use linux-arm or linux-arm64 .对于 Raspberry Pi,您应该使用linux-armlinux-arm64

Though dotnet is compatible with most popular platforms, the applications still needs to be either built locally on the machine that should run it, or using the correct RID for the machine that should run.尽管dotnet与大多数流行平台兼容,但应用程序仍然需要在应该运行它的机器上本地构建,或者为应该运行的机器使用正确的 RID。

You cannot just use the same files (.dlls and such) as the ones used on your desktop computer.您不能只使用与台式计算机上使用的文件相同的文件(.dll 等)。 By default, dotnet publish uses the architecture of the machine it runs on, which is fine in all other cases than when the application needs to run on a different architecture (or OS).默认情况下, dotnet publish使用它运行的机器的体系结构,这在所有其他情况下都很好,除非应用程序需要在不同的体系结构(或操作系统)上运行。 Your Pi and your desktop computer uses different architectures.您的 Pi 和台式计算机使用不同的架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ARM处理器(Raspberry Pi 3 B)/ Ubuntu(本机没有单声道)上运行ASP.Net Web App时出错 - Error in running ASP.Net Web App on ARM processor (Raspberry Pi 3 B) / Ubuntu (Natively without Mono) Linux 上的 ASP.NET Core MVC 应用程序 - Raspberry Pi 显示不正确 - ASP.NET Core MVC App on Linux - Raspberry Pi Not displaying correctly 带有Kestrel Web服务器的Rasberry PI上Ubuntu上的ASP.NET Core应用程序 - ASP.NET Core app on Ubuntu on Rasberry PI with Kestrel Web Server 如何在Raspberry PI 3的Windows 10 IoT核心版中从ASP.NET Core 2.1调用UWP函数 - How to call UWP function from ASP.NET Core 2.1 in Windows 10 IoT Core for Raspberry PI 3 如何在Ubuntu上运行已经开发的ASP.NET Core应用程序? - How to run already developed ASP.NET Core app on Ubuntu? .NET Core应用程序远程部署到Raspberry Pi上的Windows IoT Core - .NET Core app remote deployment to Windows IoT Core on Raspberry Pi 如何在树莓派中运行 ASP.net 网站 - How to run an ASP.net website in Raspberry pi 将.Net Core Console App部署到Raspberry PI和远程调试 - Deploy .Net Core Console App to Raspberry PI and Remote Debug 在Raspberry Pi上的.Net Core应用程序中忽略了Console.ReadLine - Console.ReadLine ignored in .Net Core app on Raspberry Pi 如何在 Raspberry PI 上运行 .net core 3.1 应用程序? - How to run .net core 3.1 app on Raspberry PI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM