总结如下:
sudo yum install libunwind libicu #安装libunwind,libicu包 curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131 #下载dotnet-dev-centos-x64.1.0.0-preview2-003121.tar文件,有时会因为网络问题下载较慢,耐心等待即可,当然也可以手动下载后放到目录下。 sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet #创建目录并解压已下载文件 sudo ln -s /opt/dotnet/dotnet /usr/local/bin #将目录链接到$PATH下,否则dotnet命令无法识别 mkdir hwapp cd hwapp dotnet new #创建默认.NET Core应用 dotnet restore #还原依赖包 dotnet run #运行,结果将显示Hello World! dotnet --info 可使用dotnet --info查看是否链接成功
附送文档参考:
.net Core 安装包下载地址: https://www.microsoft.com/net/download/core
运行命令教程: https://www.microsoft.com/net/core#windowscmd
.net 文档:https://docs.microsoft.com/zh-cn/dotnet/
具体流程如下:
[root@vm ~]# sudo yum install libunwind libicu [root@vm ~]# curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131 [root@vm ~]# mv dotnet-dev-centos-x64.1.0.0-preview2-003121.tar.gz dotnet.tar.gz mv:是否覆盖"dotnet.tar.gz"? y [root@vm ~]# ls 1.c 2.c 3.c anaconda-ks.cfg a.out dotnet.tar.gz initial-setup-ks.cfg mysql-community-release-el7-5.noarch.rpm [root@vm ~]# sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet [root@vm ~]# sudo ln -s /opt/dotnet/dotnet /usr/local/bin [root@vm ~]# mkdir hwapp [root@vm ~]# cd hwapp [root@vm hwapp]# dotnet new ▽ Welcome to .NET Core! --------------------- Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs. Telemetry -------------- The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community. You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell. You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry. Configuring... ------------------- A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once. Decompressing 100% 5628 ms Expanding 100% 55942 ms Created new C# project in /root/hwapp. [root@vm hwapp]# ls Program.cs project.json [root@vm hwapp]# cat Program.cs using System; namespace ConsoleApplication ▽ public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } [root@vm hwapp]# ls Program.cs project.json [root@vm hwapp]# cat project.json { "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.0": { ▽ "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "imports": "dnxcore50" } } } [root@vm hwapp]# dotnet restore log : Restoring packages for /root/hwapp/project.json... log : Writing lock file to disk. Path: /root/hwapp/project.lock.json log : /root/hwapp/project.json log : Restore completed in 1416ms. [root@vm hwapp]# ls Program.cs project.json project.lock.json [root@vm hwapp]# vim Program.cs using System; namespace ConsoleApplication ▽ public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } ~ [root@vm hwapp]# ls Program.cs project.json project.lock.json [root@vm hwapp]# vim project.json { "version": "1.0.0-*", "buildOptions": { "debugType": "portable", ▽ "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "imports": "dnxcore50" } } } ~ [root@vm hwapp]# ls Program.cs project.json project.lock.json [root@vm hwapp]# vim project.lock.json { "locked": false, "version": 2, "targets": { ".NETCoreApp,Version=v1.0": { "Libuv/1.9.0": { "type": "package", "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1" }, "runtimeTargets": { "runtimes/osx/native/_._": { "assetType": "native", "rid": "osx" } } }, "Microsoft.CodeAnalysis.Analyzers/1.1.0": { "type": "package" }, "Microsoft.CodeAnalysis.Common/1.3.0": { "type": "package", "dependencies": { "Microsoft.CodeAnalysis.Analyzers": "1.1.0", "System.AppContext": "4.1.0", "System.Collections": "4.0.11", "System.Collections.Concurrent": "4.0.12", "System.Collections.Immutable": "1.2.0", "System.Console": "4.0.0", "System.Diagnostics.Debug": "4.0.11", "System.Diagnostics.FileVersionInfo": "4.0.0", "System.Diagnostics.StackTrace": "4.0.1", "System.Diagnostics.Tools": "4.0.1", "System.Dynamic.Runtime": "4.0.11", "System.Globalization": "4.0.11", "System.IO.FileSystem": "4.0.1", "System.IO.FileSystem.Primitives": "4.0.1", "System.Linq": "4.1.0", "System.Linq.Expressions": "4.1.0", "System.Reflection": "4.1.0", "System.Reflection.Metadata": "1.3.0", "System.Reflection.Primitives": "4.0.1", "System.Resources.ResourceManager": "4.0.1", "System.Runtime": "4.1.0", "System.Runtime.Extensions": "4.1.0", "System.Runtime.Handles": "4.0.1", "System.Runtime.InteropServices": "4.1.0", "System.Runtime.Numerics": "4.0.1", "System.Security.Cryptography.Algorithms": "4.2.0", "System.Security.Cryptography.Encoding": "4.0.0", "System.Security.Cryptography.X509Certificates": "4.1.0", "System.Text.Encoding": "4.0.11", "System.Text.Encoding.CodePages": "4.0.1", "System.Text.Encoding.Extensions": "4.0.11", "System.Threading": "4.0.11", "System.Threading.Tasks": "4.0.11", "System.Threading.Tasks.Parallel": "4.0.1", "System.Threading.Thread": "4.0.0", "System.Xml.ReaderWriter": "4.0.11", "System.Xml.XDocument": "4.0.11", "System.Xml.XPath.XDocument": "4.0.1", "System.Xml.XmlDocument": "4.0.1" }, "compile": { "lib/netstandard1.3/_._": {} }, "runtime": { "lib/netstandard1.3/_._": {} } }, "Microsoft.CodeAnalysis.CSharp/1.3.0": { "type": "package", "dependencies": { "Microsoft.CodeAnalysis.Common": "[1.3.0]" }, "compile": { "lib/netstandard1.3/_._": {} }, "runtime": { "lib/netstandard1.3/_._": {} } }, "Microsoft.CodeAnalysis.VisualBasic/1.3.0": { "type": "package", "dependencies": { "Microsoft.CodeAnalysis.Common": "1.3.0" }, "compile": { "lib/netstandard1.3/_._": {} }, "runtime": { "lib/netstandard1.3/_._": {} } }, [root@vm hwapp]# ls Program.cs project.json project.lock.json [root@vm hwapp]# dotnet run Project hwapp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing Compiling hwapp for .NETCoreApp,Version=v1.0 Compilation succeeded. 0 Warning(s) 0 Error(s) Time elapsed 00:00:03.5667440 Hello World! [root@vm hwapp]# dotnet run Project hwapp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. Hello World! [root@vm hwapp]# dotnet --info .NET Command Line Tools (1.0.0-preview2-003121) Product Information: Version: 1.0.0-preview2-003121 Commit SHA-1 hash: 1e9d529bc5 Runtime Environment: OS Name: centos OS Version: 7 OS Platform: Linux RID: centos.7-x64