[New] starting from the virtual machine, the. Net Core program is run step by step on CentOS, centoscore
Background
After Microsoft released core June 26 in 1.0, the articles in the Garden became even more popular. From the perspective of the number of articles and the enthusiasm of interaction, it was definitely the most popular technology No. 1. I have been in touch with. net core since the end of last year for more than half a year now. I 've been stuck in browsing various posts and occasionally creating a new project and testing several lines of code. However, the biggest selling point of core, cross-platform, has never been able to experience it for a while, because it has never been used to Linux, and does not even play with those commands or even virtual machines, how difficult is it to perform operations on Linux. Although many articles in the garden have tutorials, the great gods directly started to use various command codes. They don't understand them. They don't know how to get started... But these are not the reasons to block yourself, so let's start step by step from installing a virtual machine. There are all kinds of questions in the middle, so we have a summary record.
[I would like to thank keyou Tao ge of the university dormitory and allen, the company's architect, for their assistance!]
There is a lot of nonsense. We will officially launch the workshop below...
1. Activate Hyper-V Virtual Machine management tools in windows. (Of course, Microsoft prefers its own tools ).
2. Download the image file of CentOS:
Http://mirrors.aliyun.com/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-DVD-1511.iso
3. Create a Virtual Machine (centos) in Hyper-V, set the parameters of the virtual machine, start the Virtual Machine installation system, and configure the System user (root by default ).
4. After the installation is successful, connect to centos and the following logon request appears:
Log on to the system with a Set Account (I am root here). After Successful Logon, the information about the last logon is displayed:
5. At this time, the virtual machine does not have a network. We need to create a new network adapter and assign it to the virtual machine:
Then a vswitch is added to the local network connection:
Specify an ip address of the same network segment and restart the virtual machine. After logging on, set network parameters and enter the following command:
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0 // edit the configuration file
Click ESC to exit the editing process and enter the command ": wq" to save the editing process. Run the following command to restart the network ):
# Service network restart
Ping Baidu's domain name to see if it can be connected to the network. You must be able to access the Internet, because the dependent assembly needs to be downloaded from the Internet during subsequent restore.
6. the built-in black and white screen is very difficult to use. At this time, a magic tool will be available-XShell, download and install it on your own, and then create a new connection to connect to the virtual machine. After the connection is successful:
7, the machine is ready, next we need to configure the dotNet Core environment, that is to install an SDK, we go to the official website to download the latest, address: https://go.microsoft.com/fwlink? The downloaded file name is dotnet-dev-centos-x64.1.0.0-preview2-003121.tar.gz. There are two methods to download files from a virtual machine. The first method is to use the wget command (we recommend that you feel the pleasure of using commands, hhhh ~), The wget tool must be installed on the machine. The second method is to use ftp for data transmission. At this time, Xshell's partner Xftp needs to be used. After downloading and installing it, open ftp from here:
Those who have used the ftp tool are too familiar with the interface and automatically connect to the virtual machine. This makes file operations on the Virtual Machine much easier, I am not familiar with linux commands.
8. Create a folder named "dotnet" under root to put the SDK. Then, use ftp to upload the SDK compressed package from the local machine. Then run the following command to decompress the package, open xshell, and input it in sequence:
# Cd dotnet // enter the dotnet directory
# Tar zxf dotnet-dev-centos-x64.1.0.0-preview2-003121.tar.gz // extract the file
After decompression, set the environment variables and enter the following command:
# Vi/etc/profile // open the file and edit it
Add:
PATH = ~ /Dotnet: $ PATH // dotnet is the SDK directory
Export PATH
Then press "ESC" to exit the editing and enter the command ": wq" to save the editing. Run the following command to make the configuration take effect immediately (if not, restart the VM ):
# Source/etc/profile
In this way, the environment is configured and you can test whether the "dotnet" command can be used. Enter:
# Dotnet -- version // view the dotnet version
If the installation is successful, the current number will be printed:
9. Everything has a program that only owes money! Create a new console program. In the root directory, enter:
# Mkdir dotnetcore_app // create a folder
# Cd dotnetcore_app // enter the file
# Dotnet new // create a core console Project
# Dotnet restore // download the dependency package of the program from nuget
# Dotnet build // compile the project
# Dotnet run // run the project
I am so excited to see "hello world.
10. Next, I want to run a web project for fun. I checked the command to create a web project and installed Yeoman and npm, so I won't install them first, only use ftp to upload the locally created Project to the virtual machine, and then restore:
Then build:
Then run:
You can see that the listening port 5000 (the default program) has been opened, indicating that the program is running and the virtual machine can access this address, but the physical machine cannot identify the localhost of the virtual machine, so it cannot be accessed directly in the browser of the physical machine. What should I do?
11. Find the main method of program in the program and add the Virtual Machine address and port to the host. Make sure to include http: //; otherwise, the compilation reports an error:
12. re-build and run it again:
13. access the website through a local browser:
It took about one day before and after, and only recorded the steps for smooth operation. There were too many ups and downs in the middle, but the most happy thing was that they finally achieved their goals.
Summary
1. One step at a time, we will always see the dawn of light.
2. If you step into the trap, you will be more experienced and impressed.
3. Restarting the system is sometimes a very effective troubleshooting method.
I am so excited when I first published an article on the blog ~
Finally, I hope that it will help many. net programmers who do not know linux but want to try. net core. Let's learn and make progress together!