目前只支持 OpenWrt x86_64, 所以只能在软路由上跑。 等微软发布ARM/ARM64 的.NET Core musl binary后就可以在普通家用路由器上运行了(只要内存够大)
在路由器上安装依赖
root@OpenWrt:/# opkg install lttng-ust libopenssl libstdcpp zlib libintl-full
发布项目时需加上参数 -r linux-musl-x64
dotnet publish -c Release -f netcoreapp2.1 -r linux-musl-x64
将生成的文件 bin\Release\netcoreapp2.1\linux-musl-x64\publish 全部复制到路由器上
先执行测试
root@OpenWrt:/# /mnt/sdb1/publish/myWebApp --urls http://0.0.0.0:81
添加启动项:
编写一个rc脚本 /etc/init.d/aspdotnet
#!/bin/sh /etc/rc.common USE_PROCD=1 START=99 STOP=10 start_service() { procd_open_instance procd_set_param command /mnt/sdb1/publish/myWebApp --urls http://0.0.0.0:81 procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param limits core="unlimited" procd_set_param stdout 1 procd_set_param stderr 1 procd_close_instance }
赋予可执行权限
root@OpenWrt:/# chmod +x /etc/init.d/aspdotnet
启用服务,运行服务
root@OpenWrt:/# /etc/init.d/aspdotnet enable root@OpenWrt:/# /etc/init.d/aspdotnet start
然后就可以访问 http://路由器地址:81/ 访问了