鸟语天空
Ubuntu部署.Net运行环境
post by:追风剑情 2024-7-20 16:49

一、更新apt

sudo add-apt-repository main
sudo add-apt-repository universe
sudo add-apt-repository restricted
sudo add-apt-repository multiverse
sudo apt-get update
sudo apt update  

二、安装工具包 (可选)

//安装lrzsz以便使用Xshell上传/下载文件
sudo apt install lrzsz
//安装zip包
sudo apt install zip 

三、查看系统版本号

//查看 ubuntu 版本号
lsb_release -r 

四、注册微软密钥和软件仓库

//需要将{version}替换成当前ubuntu的系统版本号,例如 22.04
wget https://packages.microsoft.com/config/ubuntu/{version}/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb 

五、安装dotnet-runtime和dotnet-sdk

sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-runtime-8.0 && \
sudo apt-get install -y dotnet-sdk-8.0 

dotnet-sdk默认安装路径为/usr/lib/dotnet 。如果只想运行dotnet程序,只需安装dotnet-runtime。

五、检查是否安装成功

//查看dotnet版本号
dotnet --version
//查看.dotnet信息
dotnet --info
//查看dotnet-runtime
dotnet --list-runtimes
//查看dotnet-sdk
dotnet --list-sdks 

六、运行dotnet程序

dotnet XXXX.dll 

运行测试程序
33333.png

七、已知问题

如果运行dotnet程序报错
You must install or update .NET to run this application
222222.png
需要检查下开发所使用的dotnet-sdk版本与ubuntu上安装的版本是否一致。

八、更多dotnet命令

Usage: dotnet [sdk-options] [command] [command-options] [arguments]

Execute a .NET SDK command.

sdk-options:
  -d|--diagnostics  Enable diagnostic output.
  -h|--help         Show command line help.
  --info            Display .NET information.
  --list-runtimes   Display the installed runtimes.
  --list-sdks       Display the installed SDKs.
  --version         Display .NET SDK version in use.

SDK commands:
  add               Add a package or reference to a .NET project.
  build             Build a .NET project.
  build-server      Interact with servers started by a build.
  clean             Clean build outputs of a .NET project.
  format            Apply style preferences to a project or solution.
  help              Show command line help.
  list              List project references of a .NET project.
  msbuild           Run Microsoft Build Engine (MSBuild) commands.
  new               Create a new .NET project or file.
  nuget             Provides additional NuGet commands.
  pack              Create a NuGet package.
  publish           Publish a .NET project for deployment.
  remove            Remove a package or reference from a .NET project.
  restore           Restore dependencies specified in a .NET project.
  run               Build and run a .NET project output.
  sdk               Manage .NET SDK installation.
  sln               Modify Visual Studio solution files.
  store             Store the specified assemblies in the runtime package store.
  test              Run unit tests using the test runner specified in a .NET project.
  tool              Install or manage tools that extend the .NET experience.
  vstest            Run Microsoft Test Engine (VSTest) commands.
  workload          Manage optional workloads.

Additional commands from bundled tools:
  dev-certs         Create and manage development certificates.
  fsi               Start F# Interactive / execute F# scripts.
  user-jwts         Manage JSON Web Tokens in development.
  user-secrets      Manage development user secrets.
  watch             Start a file watcher that runs a command when files change.

Run 'dotnet [command] --help' for more information on a command.
 
评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容