安装 .NET Core SDK
安装:
$ sudo pacman -S dotnet-sdk
查看版本信息:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6
Runtime Environment:
OS Name: arch
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /opt/dotnet/sdk/2.1.301/
Host (useful for support):
Version: 2.1.1
Commit: 6985b9f684
.NET Core SDKs installed:
2.1.301 [/opt/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.1 [/opt/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
我的第一个 .NET Core 程序
$ cd src/dotnet
$ dotnet new console -o clrversion
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on clrversion/clrversion.csproj...
Restoring packages for /home/ben/src/dotnet/clrversion/clrversion.csproj...
Generating MSBuild file /home/ben/src/dotnet/clrversion/obj/clrversion.csproj.nuget.g.props.
Generating MSBuild file /home/ben/src/dotnet/clrversion/obj/clrversion.csproj.nuget.g.targets.
Restore completed in 273.53 ms for /home/ben/src/dotnet/clrversion/clrversion.csproj.
Restore succeeded.
$ cd clrversion
$ dotnet run
Hello World!
将 Program.cs 中 Main 函数的内容改为:
Console.WriteLine("OS : " + Environment.OSVersion);
Console.WriteLine("CLR: " + Environment.Version);
再次运行:
$ dotnet run
OS : Unix 4.17.3.1
CLR: 4.0.30319.42000
dotnet --info 和都成功了
但把Program.cs的内容替换成E708.cs的内容后
C:\Downloads\net>cd clrversion
C:\Downloads\net\clrversion>dotnet run
'dotnet' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Downloads\net\clrversion>..\dotnet run
A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Downloads\net\clrversion\bin\Debug\netcoreapp
3.1\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program Files\dotnet] or use the DOTNET
_ROOT environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\Installed
Versions\x86\InstallLocation].
The .NET Core runtime can be found at:
- https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x86&rid=win7-x86
是还需要装runtime吗?
改成
Console.WriteLine("OS : " + Environment.OSVersion);
Console.WriteLine("CLR: " + Environment.Version);
也是一样的效果