Set up an ASP. NET 5 Development Environment In Ubuntu,
Build an ASP. NET 5 development environment in Ubuntu 0x00.
At the end of the year, I was so busy that I had no time to learn what I was interested in. So I didn't even write my blog. Recently, there was a small function to be used as a Web application. Previously, similar requirements were raised. At that time, WCF was used for WebAPI and ExtJS was used for the front-end. This requirement is not critical, as long as the problem can be solved, the specific technology does not matter, just catch up with ASP. NET 5 release, so I plan to try it. In Windows, the powerful VS solution is used to solve the problem. However, ASP. NET5 is a cross-platform solution. I decided to try to deploy the development environment in Linux. In the future, it will be more convincing to fool others. I have been using Windows for a long time. I just installed Linux out of curiosity. So I am not very familiar with Linux. I checked and did it. During this period, I naturally encountered various pitfalls and had a hard time working for more than a day, however, we finally ran it. here we will record the pitfalls we encountered, the solutions we encountered, and the unsolved problems.
0x01 Windows and Ubuntu
I used virtual machines to install Linux. Now I want to test it carefully. I have allocated GB space from the hard disk and installed Ubuntu dual-system according to the tutorial on the Internet. However, this is not the focus of this article, and it is easy to find a large number of tutorials. This article I refer:
Http://www.linuxidc.com/Linux/2012-05/59663.htm
0x02 install the ASP. NET 5 Development Environment
The following focuses on the process. Refer to Microsoft's official documentation for the main steps:
Https://docs.asp.net/en/latest/getting-started/installing-on-linux.html
First, let's explain the first pitfall we step on. Because many commands require sudo, sudo bash switches the terminal to the root, the consequence is that some of the folders created later are root, resulting in a permission error when using yo to create a project under non-root, which took a lot of time to locate the problem. Therefore, we recommend that you use sudo in an honest and practical manner to avoid unnecessary troubles. We can see below that I still use the root. Don't do this.
1. Install DNVM
First, prepare the tools used to build the development environment. In general, the system is likely to come with it, but in case it is still running, it is also very fast:
sudo apt-get install unzip curl
This command installs the unzip and curl tools for decompression and download.
What is DNVM, DNX can refer to @ Zhang Shanyou this article http://www.cnblogs.com/shanyou/p/4589930.html to write a very comprehensive
Download DNVM. The official website provides the following commands:
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
The prepared curl is used here, but the general system comes with it.
Follow the system prompts to execute the command after the download
source ~/.dnx/dnvm/dnvm.sh
In this way, the DNVM installation is complete. You can enter dnvm to check whether the installation is successful.
2. Use DNVM to install DNX
First, you need to prepare the tools used for installation.
sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev
Then install DNX for. NET Core with DNVM
dnvm upgrade -r coreclr
Then install DNX for Mono using DNVM
dnvm upgrade -r mono
During installation, the system prompts that Mono is not in my system and you need to install it. Follow the link provided in the official website documents and execute the following commands in sequence:
apt-key adv --keyserver keyserver.ubuntu.com –recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EFecho "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.listapt-get updateapt-get install Mono-Complete
3. Install libuv
Why is this installation required? Because Local Web service testing is required during development. In Windows, We have IIS Express, but not in Linux. The official recommendation is kestrel, and kestrel uses the libuv library, so we need to install this library. This library is installed by source code compilation. There are many commands. Anyway, I copied them in one line. Basically, after copying the next command, the previous command was executed, the experience is also good: the general process is: Install the tools required for compilation, download and decompress the source code, compile and install, and load the shared library to make the new library take effect.
sudo apt-get install make automake libtool curlcurl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/srccd /usr/local/src/libuv-1.4.2sudo sh autogen.shsudo ./configuresudo makesudo make installsudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/sudo ldconfig
Now we have installed the ASP. NET 5 development environment. Is that the end? At the beginning, I thought so too, but I realized right away. When I want to create a test project, I find that I cannot start with it. On Windows, I use VS to create a solution, select the Web, and then select the template to use, but there is no template in Linux. You cannot create one file manually. Then, read the document and find out the Your First APS. NET 5 Application on XXX series, but there is no Linux in it. It should be okay to refer to Mac.
Https://docs.asp.net/en/latest/tutorials/your-first-mac-aspnet.html
0x03 install and configure development tools
The development tool is actually Visula Studio Code, which is downloaded from the official website.
Https://code.visualstudio.com/
Decompress the package and run the Code directly.
The template generated during project creation is generated by yeoman. Npm is required for yeoman installation, so we should install npm first.
sudo apt-get install npm
Npm and nodejs are mutually dependent, and any one of them will be installed automatically. After installation, you can use
npm install -g yo bower grunt-cli gulp
Install yeoman, bower, grunt-cli, and gulp. However, the problem is that yeoman requires nodejs Versions later than 0.12, while the version installed with apt-get is only 0.10, including the use of the legendary n name, which is said to be dedicated to upgrading nodejs tools. I found this article on the Internet:
Http://my.oschina.net/tbaby/blog/412052
There is such a command:
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
I opened the https://deb.nodesource.com and looked at it.
After the above command is downloaded, a prompt is displayed.
Run this command
sudo apt-get install nodejs
You can install the latest nodejs version. The latest version 0.12.9 has been installed.
In this way, you can use npm to install a series of tools such as yeoman. The command is as follows:
npm install -g yo bower grunt-cli gulp
Yeoman is installed, but yeoman cannot generate a template for ASP. NET, which also needs to be installed. Run the following command to install the ASP. NET template:
npm install -g generator-aspnet
After the installation is complete, we can use yeoman to create a project. Go to the directory where we want to place the project and run
yo aspnet
Then we can see the Template Selection interface. When we select WebApplication, we will be prompted to enter the application name, we enter first, and then yeoman will help us create the first directory, create all the project files.
When you use VSCode to open the first directory, a message indicating a lack of dependencies is displayed.
Run the following command in the project directory:
dnu restore
In this way, the dependency problem can be solved. It may take some time to download a lot of things for the first restore.
After that, the directory structure is probably the same as that created with. The Code also prompts you to reference attributes and methods.
In the project. json file of the project, we can see the friend web command in commands, and we can also find the corresponding dependency in dependency. Use the web command to enable the kestrel service.
Run the following command in the project directory:
dnx web
You can enable the web service so that you can enter localhost: 5000 in the browser to view our page.
Try to change the About message in HomeController. You must restart the Web service to make it take effect. It is better to use VS. You can directly save VS and refresh F5 to see the effect, just like using Script Development.
The strange thing is that after you switch dnx to coreclr, the input of dnx does not reflect any reflection, and no problem is found on the Internet. Please kindly advise if you know anything.
------------ = ------- Updated on April 21 ----------------------
Thanks to the solution provided by @ zwmyxzs, @ zwmyxzs has previously written an article on this issue: ubuntu15 coreclr.
Because coreclr is compatible with Ubuntu14, I use Ubuntu15, and unbuntu14 uses libicu52, while unbuntu15 is libicu55, you only need to install libicu52.
wget http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu52_52.1-8ubuntu0.2_amd64.debdpkg -i libicu52_52.1-8ubuntu0.2_amd64.deb
Follow the method given by @ zwmyxzs.
Use coreclr to run the service normally
0x04 finally written nonsense
Since I am not very familiar with Linux, I encountered many problems in the whole process. I picked a few annoying ones. I did not mention some mentally retarded people who would expose their IQ. However, I have gained a better understanding of many concepts such as dnvm and dnx. But if I do ASP. NET 5 development, I will still choose windows. After all, there is a powerful. Finally, let's talk about how to use Ubuntu. I have been using Windows for a long time and suddenly changed to Ubuntu. I feel that it is not as difficult as I thought. The graphic interface is quite mature. Many tools can be basically solved using Web applications. The JetBrains series can be used for development, and now more VSCode is added. As long as you do not write WPF, the problem is not very serious. If you encounter any problems, you can search for them online to solve the problem. You should be familiar with it.