ubuntu 16.04下用.NET Core写C#程序

2017 微软一个比较大的动作就是.Net core2.0了,微软出的这个框架野心很大:它可以让用户在几乎所有的PC终端用C#编写自己的应用程序。在win/linux/mac三大主流操作系统通吃之后,.Net core居然也支持Docker!
本文试着在ubuntu 16.04运行自己的C#程序,其他操作系统包括Windows,MacOS和Docker上的教程见官网:.Net Core
首先注入密钥更新系统:

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B02C46DF417A0893
sudo apt-get update

然后安装.Net SDK:

sudo apt-get install dotnet-dev-2.0 #安装最新2.0预览版

接着创建你的项目,一般第一个项目就是黑框框打印”hello world”,那我们就把项目类型指定为”console”,类似于vs中的控制台项目。

dotnet new console -o firstapp

执行完这条命令后,打印如下:

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 command-line 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% 5047 ms
Expanding 100% 8946 ms
Getting ready...
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on firstapp/firstapp.csproj...
Restore succeeded.

执行tree ..命令,查看项目结构,可以看到:

..
└── firstapp
    ├── firstapp.csproj
    ├── obj
    │   ├── firstapp.csproj.nuget.g.props
    │   ├── firstapp.csproj.nuget.g.targets
    │   └── project.assets.json
    └── Program.cs

在你的Program.cs中编写你的程序,这里其实已经自动生成了”Hello World!”的打印代码。
然后执行以下命令,程序就会在终端打印”hello world”:

cd firstapp
dotnet restore
dotnet run 

在首次运行时候会创建一个Nugut.Config文件,详细打印如下:

# dotnet restore
  Restoring packages for /home/Csharp/firstapp/firstapp.csproj...
  Lock file has not changed. Skipping lock file write. Path: /home/Csharp/firstapp/obj/project.assets.json
  Restore completed in 93.44 ms for /home/Csharp/firstapp/firstapp.csproj.

  NuGet Config files used:
      /root/.nuget/NuGet/NuGet.Config

  Feeds used:
      https://api.nuget.org/v3/index.json
      /root/.dotnet/NuGetFallbackFolder
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值