mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-10 22:21:11 +08:00
translated
This commit is contained in:
parent
4d025fbe9d
commit
78feb07abb
@ -1,170 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to start developing with .NET)
|
||||
[#]: via: (https://opensource.com/article/19/9/getting-started-net)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/sethhttps://opensource.com/users/alex-bunardzichttps://opensource.com/users/alex-bunardzic)
|
||||
|
||||
How to start developing with .NET
|
||||
======
|
||||
Learn the basics to get up and running with the .NET development
|
||||
platform.
|
||||
![Coding on a computer][1]
|
||||
|
||||
The .NET framework was released in 2000 by Microsoft. An open source implementation of the platform, [Mono][2], was the center of controversy in the early 2000s because Microsoft held several patents for .NET technology and could have used those patents to end Mono implementations. Fortunately, in 2014, Microsoft declared that the .NET development platform would be open source under the MIT license from then on, and in 2016, Microsoft purchased Xamarin, the company that produces Mono.
|
||||
|
||||
Both .NET and Mono have grown into cross-platform programming environments for C#, F#, GTK#, Visual Basic, Vala, and more. Applications created with .NET and Mono have been delivered to Linux, BSD, Windows, MacOS, Android, and even some gaming consoles. You can use either .NET or Mono to develop .NET applications. Both are open source, and both have active and vibrant communities. This article focuses on getting started with Microsoft's implementation of the .NET environment.
|
||||
|
||||
### How to install .NET
|
||||
|
||||
The .NET downloads are divided into packages: one containing just a .NET runtime, and the other a .NET software development kit (SDK) containing the .NET Core and runtime. Depending on your platform, there may be several variants of even these packages, accounting for architecture and OS version. To start developing with .NET, you must [install the SDK][3]. This gives you the [dotnet][4] terminal or PowerShell command, which you can use to create and build projects.
|
||||
|
||||
#### Linux
|
||||
|
||||
To install .NET on Linux, first, add the Microsoft Linux software repository to your computer.
|
||||
|
||||
On Fedora:
|
||||
|
||||
|
||||
```
|
||||
$ sudo rpm --import <https://packages.microsoft.com/keys/microsoft.asc>
|
||||
$ sudo wget -q -O /etc/yum.repos.d/microsoft-prod.repo <https://packages.microsoft.com/config/fedora/27/prod.repo>
|
||||
```
|
||||
|
||||
On Ubuntu:
|
||||
|
||||
|
||||
```
|
||||
$ wget -q <https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb> -O packages-microsoft-prod.deb
|
||||
$ sudo dpkg -i packages-microsoft-prod.deb
|
||||
```
|
||||
|
||||
Next, install the SDK using your package manager, replacing **<X.Y>** with the current version of the .NET release:
|
||||
|
||||
On Fedora:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo dnf install dotnet-sdk-<X.Y>`
|
||||
```
|
||||
|
||||
On Ubuntu:
|
||||
|
||||
|
||||
```
|
||||
$ sudo apt install apt-transport-https
|
||||
$ sudo apt update
|
||||
$ sudo apt install dotnet-sdk-<X.Y>
|
||||
```
|
||||
|
||||
Once all the packages are downloaded and installed, confirm the installation by opening a terminal and typing:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet --version
|
||||
X.Y.Z
|
||||
```
|
||||
|
||||
#### Windows
|
||||
|
||||
If you're on Microsoft Windows, you probably already have the .NET runtime installed. However, to develop .NET applications, you must also install the .NET Core SDK.
|
||||
|
||||
First, [download the installer][3]. To keep your options open, download .NET Core for cross-platform development (the .NET Framework is Windows-only). Once the **.exe** file is downloaded, double-click it to launch the installation wizard, and click through the two-step install process: accept the license and allow the install to proceed.
|
||||
|
||||
![Installing dotnet on Windows][5]
|
||||
|
||||
Afterward, open PowerShell from your Application menu in the lower-left corner. In PowerShell, type a test command:
|
||||
|
||||
|
||||
```
|
||||
`PS C:\Users\osdc> dotnet`
|
||||
```
|
||||
|
||||
If you see information about a dotnet installation, .NET has been installed correctly.
|
||||
|
||||
#### MacOS
|
||||
|
||||
If you're on an Apple Mac, [download the Mac installer][3], which comes in the form of a **.pkg** package. Download and double-click on the **.pkg** file and click through the installer. You may need to grant permission for the installer since the package is not from the App Store.
|
||||
|
||||
Once all packages are downloaded and installed, confirm the installation by opening a terminal and typing:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet --version
|
||||
X.Y.Z
|
||||
```
|
||||
|
||||
### Hello .NET
|
||||
|
||||
A sample "hello world" application written in .NET is provided with the **dotnet** command. Or, more accurately, the command provides the sample application.
|
||||
|
||||
First, create a project directory and the required code infrastructure using the **dotnet** command with the **new** and **console** options to create a new console-only application. Use the **-o** option to specify a project name:
|
||||
|
||||
|
||||
```
|
||||
`$ dotnet new console -o hellodotnet`
|
||||
```
|
||||
|
||||
This creates a directory called **hellodotnet** in your current directory. Change into your project directory and have a look around:
|
||||
|
||||
|
||||
```
|
||||
$ cd hellodotnet
|
||||
$ dir
|
||||
hellodotnet.csproj obj Program.cs
|
||||
```
|
||||
|
||||
The file **Program.cs** is an empty C# file containing a simple Hello World application. Open it in a text editor to view it. Microsoft's Visual Studio Code is a cross-platform, open source application built with dotnet in mind, and while it's not a bad text editor, it also collects a lot of data about its user (and grants itself permission to do so in the license applied to its binary distribution). If you want to try out Visual Studio Code, consider using [VSCodium][6], a distribution of Visual Studio Code that's built from the MIT-licensed source code _without_ the telemetry (read the [documentation][7] for options to disable other forms of tracking in even this build). Alternatively, just use your existing favorite text editor or IDE.
|
||||
|
||||
The boilerplate code in a new console application is:
|
||||
|
||||
|
||||
```
|
||||
using System;
|
||||
|
||||
namespace hellodotnet
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To run the program, use the **dotnet run** command:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet run
|
||||
Hello World!
|
||||
```
|
||||
|
||||
That's the basic workflow of .NET and the **dotnet** command. The full [C# guide for .NET][8] is available, and everything there is relevant to .NET. For examples of .NET in action, follow [Alex Bunardzic][9]'s mutation testing articles here on opensource.com.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/getting-started-net
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/sethhttps://opensource.com/users/alex-bunardzichttps://opensource.com/users/alex-bunardzic
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_laptop_hack_work.png?itok=aSpcWkcl (Coding on a computer)
|
||||
[2]: https://www.monodevelop.com/
|
||||
[3]: https://dotnet.microsoft.com/download
|
||||
[4]: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet?tabs=netcore21
|
||||
[5]: https://opensource.com/sites/default/files/uploads/dotnet-windows-install.jpg (Installing dotnet on Windows)
|
||||
[6]: https://vscodium.com/
|
||||
[7]: https://github.com/VSCodium/vscodium/blob/master/DOCS.md
|
||||
[8]: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/
|
||||
[9]: https://opensource.com/users/alex-bunardzic (View user profile.)
|
170
translated/tech/20190916 How to start developing with .NET.md
Normal file
170
translated/tech/20190916 How to start developing with .NET.md
Normal file
@ -0,0 +1,170 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to start developing with .NET)
|
||||
[#]: via: (https://opensource.com/article/19/9/getting-started-net)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/sethhttps://opensource.com/users/alex-bunardzichttps://opensource.com/users/alex-bunardzic)
|
||||
|
||||
如何开始使用 .NET 进行开发
|
||||
======
|
||||
了解 .NET 开发平台启动和运行的基础知识。
|
||||
![Coding on a computer][1]
|
||||
|
||||
.NET 框架由 Microsoft 于 2000 年发布。该平台的开源实现 [Mono][2] 在 21 世纪初成为了争议的焦点,因为微软拥有 .NET 技术的多项专利,并且可能使用这些专利来结束 Mono。幸运的是,在 2014 年,微软宣布 .NET 开发平台从此成为 MIT 许可下的开源平台,并在 2016 年收购了开发 Mono 的 Xamarin 公司。
|
||||
|
||||
.NET 和 Mono 已经同时可用于 C#、F#、GTK+、Visual Basic、Vala 等的跨平台编程环境。使用 .NET 和 Mono 创建的程序已经应用于 Linux、BSD、Windows、MacOS、Android,甚至一些游戏机。你可以使用 .NET 或 Mono 来开发 .NET 应用。它们都是开源的,并且都有活跃和充满活力的社区。本文重点介绍 Microsoft .NET 环境实现。
|
||||
|
||||
### 如何安装 .NET
|
||||
|
||||
.NET 下载被分为多个包:一个仅包含 .NET 运行时,另一个包含了 .NET Core 和运行时 .NET SDK。根据架构和操作系统版本,这些包可能有多个版本。要开始使用 .NET 进行开发,你必须[安装 SDK][3]。它为您提供了 [dotnet][4] 终端或 PowerShell 命令,你可以使用它们来创建和生成项目。
|
||||
|
||||
#### Linux
|
||||
|
||||
要在 Linux 上安装 .NET,首先将 Microsoft Linux 软件仓库添加到你的计算机。
|
||||
|
||||
在 Fedora 上:
|
||||
|
||||
|
||||
```
|
||||
$ sudo rpm --import <https://packages.microsoft.com/keys/microsoft.asc>
|
||||
$ sudo wget -q -O /etc/yum.repos.d/microsoft-prod.repo <https://packages.microsoft.com/config/fedora/27/prod.repo>
|
||||
```
|
||||
|
||||
在 Ubuntu 上:
|
||||
|
||||
|
||||
```
|
||||
$ wget -q <https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb> -O packages-microsoft-prod.deb
|
||||
$ sudo dpkg -i packages-microsoft-prod.deb
|
||||
```
|
||||
|
||||
接下来,使用包管理器安装 SDK,将 **<X.Y>** 替换为当前版本的 .NET 版本:
|
||||
|
||||
在 Fedora 上:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo dnf install dotnet-sdk-<X.Y>`
|
||||
```
|
||||
|
||||
在 Ubuntu 上:
|
||||
|
||||
|
||||
```
|
||||
$ sudo apt install apt-transport-https
|
||||
$ sudo apt update
|
||||
$ sudo apt install dotnet-sdk-<X.Y>
|
||||
```
|
||||
|
||||
下载并安装所有包后,打开终端并输入下面命令确认安装:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet --version
|
||||
X.Y.Z
|
||||
```
|
||||
|
||||
#### Windows
|
||||
|
||||
如果你使用的是 Microsoft Windows,那么你可能已经安装了 .NET 运行时。但是,要开发 .NET 应用,你还必须安装 .NET Core SDK。
|
||||
|
||||
|
||||
首先,[下载安装程序][3]。请认准下载 .NET Core 进行跨平台开发(.NET Framework 仅适用于 Windows)。下载 **.exe** 文件后,双击该文件启动安装向导,然后单击两下进行安装:接受许可证并允许安装继续。
|
||||
|
||||
![Installing dotnet on Windows][5]
|
||||
|
||||
然后,从左下角的“应用程序”菜单中打开 PowerShell。在 PowerShell 中,输入测试命令:
|
||||
|
||||
|
||||
```
|
||||
`PS C:\Users\osdc> dotnet`
|
||||
```
|
||||
|
||||
如果你看到有关 dotnet 安装的信息,那么说明 .NET 已正确安装。
|
||||
|
||||
#### MacOS
|
||||
|
||||
如果你使用的是 Apple Mac,请下载 **.pkg**形式的 [Mac 安装程序][3]。下载并双击 **.pkg** 文件,然后单击安装程序。你可能需要授予安装程序权限,因为该软件包并非来自 App Store。
|
||||
|
||||
下载并安装所有软件包后,请打开终端并输入以下命令来确认安装:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet --version
|
||||
X.Y.Z
|
||||
```
|
||||
|
||||
### Hello .NET
|
||||
|
||||
**dotnet** 命令提供了一个用 .NET 编写的 “hello world ” 示例程序。或者,更准确地说,该命令提供了示例应用。
|
||||
|
||||
首先,使用 **dotnet** 命令以及 **new** 和 **console** 参数创建一个控制台应用的项目目录及所需的代码基础结构。使用 **-o** 选项指定项目名称:
|
||||
|
||||
|
||||
```
|
||||
`$ dotnet new console -o hellodotnet`
|
||||
```
|
||||
|
||||
这将在当前目录中创建一个名为 **hellodotnet** 的目录。进入你的项目目录并看一下:
|
||||
|
||||
|
||||
```
|
||||
$ cd hellodotnet
|
||||
$ dir
|
||||
hellodotnet.csproj obj Program.cs
|
||||
```
|
||||
|
||||
**Program.cs** 是一个空的 C# 文件,它包含了一个简单的 Hello World 程序。在文本编辑器中打开浏览。微软的 Visual Studio Code 是一个使用 dotnet 编写的跨平台的开源应用,虽然它不是一个糟糕的文本编辑器,但它会收集用户的大量数据(在它的二进制发行版的许可证中授予了自己权限)。如果要尝试使用 Visual Studio Code,请考虑使用 [VSCodium][6],它是使用 Visual Studio Code 的 MIT 许可的源码构建的版本,而_没有_远程收集(请阅读[文档][7]来禁止此构建中的其他形式追踪)。或者,只需使用现有的你最喜欢的文本编辑器或 IDE。
|
||||
|
||||
新控制台应用中的样板代码为:
|
||||
|
||||
|
||||
```
|
||||
using System;
|
||||
|
||||
namespace hellodotnet
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
要运行该程序,请使用 **dotnet run** 命令:
|
||||
|
||||
|
||||
```
|
||||
$ dotnet run
|
||||
Hello World!
|
||||
```
|
||||
|
||||
这是 .NET 和 **dotnet** 命令的基本工作流程。这里有完整的 [.NET C# 指南][8],并且都是与 .NET 相关的内容。关于 .NET 实战示例,请关注 [Alex Bunardzic][9] 在 opensource.com 中的变异测试文章。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/9/getting-started-net
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/sethhttps://opensource.com/users/alex-bunardzichttps://opensource.com/users/alex-bunardzic
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/code_computer_laptop_hack_work.png?itok=aSpcWkcl (Coding on a computer)
|
||||
[2]: https://www.monodevelop.com/
|
||||
[3]: https://dotnet.microsoft.com/download
|
||||
[4]: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet?tabs=netcore21
|
||||
[5]: https://opensource.com/sites/default/files/uploads/dotnet-windows-install.jpg (Installing dotnet on Windows)
|
||||
[6]: https://vscodium.com/
|
||||
[7]: https://github.com/VSCodium/vscodium/blob/master/DOCS.md
|
||||
[8]: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/
|
||||
[9]: https://opensource.com/users/alex-bunardzic (View user profile.)
|
Loading…
Reference in New Issue
Block a user