树莓派基于c语言开发板,在树莓派等基于ARM的开发板运行.NET Core程序

前言

本人的技术栈基本上C#方向上面的,又对树莓派之类的开发特别感兴趣,奈何C语言学的一知半解,很多东西都没法做。所以瞅上了.NET Core,毕竟跨平台,自己也熟悉C#。

依赖

首先是安装依赖。之所以把安装依赖放在前面,是因为不安装依赖的话,之后运行程序会各种报错。

sudo apt install libunwind8 libuuid1 liblttng-ust0 libcurl3 libssl1.0.0 libkrb5-3 zlib1g libicu55

安装.Net Core RunTime

这里推荐使用脚本安装, 可以自动安装对应架构对应系统的版本。按照微软团队给出的方法:

Scripting Installs with the .NET Core installer script

The dotnet-install scripts are used to perform a non-admin install of the CLI toolchain and the shared runtime. You can download the script from https://dot.net/v1/dotnet-install.sh.

获取脚本wget https://dot.net/v1/dotnet-install.sh

sudo chmod +x dotnet-install.sh

如果你只想安装runtime并不想安装sdk的话,直接执行以下命令,默认是安装LTS版本:

./dotnet-install.sh --runtime dotnet

如果runtime和sdk要一并安装的话,输入以下命令(指定版本安装):

./dotnet-install.sh --channel 2.1

安装最新版:

./dotnet-install.sh --channel Current

默认是安装到了当前用户目录的.dotnet文件夹内,所以要把当前目录添加到环境变量。

sudo export PATH="/root/.dotnet:$PATH" #注意:当前是root用户,非root用户去掉sudo和更改.dotnet位置

然后运行

sudo source /etc/profile

或者直接添加映射(推荐)

sudo ln -s /root/.dotnet/dotnet /usr/local/bin

把当前目录添加到环境变量和添加程序映射,推荐第二种。

此时输入dotnet --info应显示以下类似信息:

Usage: dotnet [options]

Usage: dotnet [path-to-application]

Options:

-h|--help Display help.

--info Display .NET Core information.

--list-sdks Display the installed SDKs.

--list-runtimes Display the installed runtimes.

path-to-application:

The path to an application .dll file to execute.

root@Neo2:/usr/local/bin# dotnet --info

.NET Core SDK (reflecting any global.json):

Version: 2.1.503

Commit: 4c506e0f35

Runtime Environment:

OS Name: ubuntu

OS Version: 16.04

OS Platform: Linux

RID: ubuntu.16.04-arm64

Base Path: /root/.dotnet/sdk/2.1.503/

Host (useful for support):

Version: 2.1.7

Commit: cca5d72d48

.NET Core SDKs installed:

2.1.503 [/root/.dotnet/sdk]

.NET Core runtimes installed:

Microsoft.NETCore.App 2.1.7 [/root/.dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:

https://aka.ms/dotnet-download

需要注意的是,这只是配置了.NET Core Runtime。

运行控制台程序

1、直接初始化项目

通过命令行直接初始化一个Hello World项目,然后运行。输入命令:

dotnet new console -o ConsoleTest

运行

cd ConsoleTest

dotnet run

2、在VS中编写.NET Core程序

创建.NET Core控制台程序

a0c45bd7363a55c3f455d7ecd55618e7.png

平台选择ARM

f6eb851acfdcd77fee3e27eb04254756.png

选择发布,将生产用于ARM的应用程序。

d923547a21a7bf7d7ff9e248686abb2f.png

在Release文件下会有一个publish的文件夹,将其上传到开发板中。然后运行dll文件。

c7326cb79aa82bb4e437a3705b5cca0b.png

踩坑

1、为什么不按照微软官方的教程按照.Net Core?

本来我是想按照微软官方的教程一步一步按照core2.1的,但是一直cannot find any package。所以只能借鉴别个的教程来安装Runtime。个人推测是因为系统和开发板的原因,手里面展暂时没有树莓派,用的是Nanopi。微软官方的教程地址:https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial#install。

617792c7397ffcfdfafbaa3799765f9f.png

2、dotnet run失败

直接初始化项目,然后run的是报错。

5b99b3ae7971b9e0106d07e3eb5f562c.png

不晓得是什么原因造成的。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值