ASP. NET Core 1.0

Source: Internet
Author: User

Running ASP. NET Core 1.0 across platforms PrefaceFirst mention the name of Microsoft after its renaming:
    • ASP. NET 5 renamed to ASP. NET Core 1.0
    • . NET core renamed. NET Core 1.0
    • Entity Framework 7 is renamed Entity Framework Core 1.0 or EF Core 1.0
Now with the update speed of ASP. NET Core 1.0 RC2, many official documents are not up to date, and are still in use in the RC1 version (RC1 version is the stable version of the first release after the beta release). The difference between RC1 and RC2 is that the RC1 version uses DNVM, DNX to restore packages and run (Dnu is included in Dnx), while the RC2 version is dotnet based on the. NET Core CLI using the building command. Compiling, NuGet package management, running, testing. If you want to learn more about the publishing progress and milestones for ASP. NET Core 1.0, you can view: ASP. NET Core 1.0 Schedule and roadmap. For now, in some systems we can already abandon mono, using only the. NET core and. NET core CLI to provide the right. NET program to build a compiled runtime environment (which contains the. NET Core SDK binaries for both. NET core and. NET core CLI, which can be downloaded here). As for the future of Mono, Microsoft's Soctthunter and Scott Hasnselman said: "Mono switching to the MIT Open Source License agreement will be part of the company's plan to build a unified. NET library in the future, learn more." The visible open source mono is gradually integrated into the. NET core System.
    • . NET Core Sdk=.net core+.net Core command-line (abbreviated Cli\.net cli\.net core cli,dotnet commands)
    • . NET core= base Class library. NET Core Framework (COREFX) + runtime. NET core runtime (CoreCLR) + compiler management (such as management compiler Roslyn) +more
This article focuses on the cross-platform deployment of the ASP. NET Core 1.0 RC2 ("Deployment Environment" as a first step, helping to understand the operating environment and mechanism of the program). If you want to learn about cross-platform deployment version RC1, see
    • Installing ASP. 5 on Cross-platform
    • Running ASP. 5 Applications in Linux Containers with Docker
    • . NET core + ASP. 1.0 RC1 Bits
The following sections describe how to deploy in Dokcer, CentOS, and Ubuntu environments, and Windows is relatively simple and not described. For example, run the ASP. NET Core program with Cli-samples Hellomvc. first, run in Docker

1. Environment

The Docker host environment shown here is CentOS7, and the installation of Docker on CentOS7 is described below. To install Docker in other systems, check out the install Docker engine tip: CentOS has enabled FIREWALLD as a new firewall in 7, replacing the original iptables. While Docker compatibility with FIREWALLD is not very good, but the following example of the operation of the temporary not found to have an impact.

2. Installing Docker

First look at the kernel version of CentOS (the CENTOS7 system must be 64 bits and the kernel must be 3.10 and above)

Uname-r3.10.0-229.el7.x86_64

To update a package that is already installed

sudo yum update  

Installing Docker

Curl-fssl https://get.docker.com/| Sh

Start Docker

sudo service docker start or Systemctl start Docker

Run Docker Hello World demo

sudo Docker run Hello-world

3. Create a Docker user group

This user group has administrator privileges, and later execution of the Docker command can be done without sudo (this is only a demonstration, directly using root) (1) Log in to the console with administrator privileges
(2) sudo usermod -aG docker Your_username (your user name)
(3) Log out and log in to the console
(4) Perform Docker run Hello-world without sudo to see if the correct output of Hello World
(5) Set boot start sudo chkconfig docker on or systemctl enable Docker

4. Docker Related concepts

Container: container, used to load various image, can be regarded as operating system. Load a variety of apps. Allows multiple containers to run at the same time, and the container generally cannot access the host server resources to each other, unless the data volume is mounted volume and so on, the use of the volume can be referred to as: http://my.oschina.net/guol/blog/271225). Some network applications can be run in the container, so that external access to these applications can be -POr -pparameter to specify the port mapping. Image: Image file that can be run as an app in container, image has a dockerfile file, the command to be executed when the passbook generates its own image. If the Docker run runs a container without the-d parameter to let it run in the background, the CTRL + C exit process also causes the container to stop, and if you exit without stopping the container you can ctrl+p and then ctrl+q.Docker Common Commands

5, make HELLOMVC image

Before running the Cli-samples Hellomvc example, you need to package the HELLOMVC into a docker image file. 5.1 First install git, clone cli-samples down
mkdir appcd appgit Clone Https://github.com/aspnet/cli-samples.gitcd cli-samples

You need to explicitly specify the port of HELLOMVC (even if you specify Port 5000), and now try not to add the following code, found that the default of 5000 does not work

5.2 Execute in the current directory of HELLOMVC and prepare the Nuget.config and Dockerfile files Nuget.config: Read the source address of the package download (NuGet seeds); Dockerfile: Make image must; 5.2.1 CreateNuget.config files can be copied from the parent directory cli-samples a nuget.config to the HELLOMVC directory, without which the nuget.config will default to when the package is restored. nuget/nuget/ Load Nuget.config. Some packeage cannot be downloaded because the source is incorrect.
Copy command cp-p  /root/app/cli-samples/nuget.config  /root/app/cli-samples/hellomvc/nuget.config  

5.2.2 Creating an Dockerfile file when you create an image, the. NET CLI Preview Docker image provides two basic dotnet image for inheritance (which is actually loaded with an Ubuntu system that deploys. NET core), The difference is that their dockerfile are different.
    • Dotnet:0.0.1-alpha
    • dotnet:0.0.1-alpha-onbuild
Dotnet:0.0.1-alpha's Dockerfile, based on BUILDPACK-DEPS:TRUSTY-SCM Dotnet:0.0.1-alpha-onbuild based on Dotnet:0.0.1-alpha, (onbuild <dockerfile keyword > onbuild the specified command does not execute when the image is built, but executes in its sub-image) so Hellomvc Dockerfile can be written in two ways, one (1) based on dotnet:0 .0.1-alpha
From Microsoft/dotnet:latestrun mkdir-p/webappcopy. /webappworkdir/webapprun ["dotnet", "Restore"]run sudo apt-get-y update     && sudo apt-get install-y dialog ma Ke automake libtool curl  RUN curl-ssl https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv--c/usr/ LOCAL/SRC      && cd/usr/local/src/libuv-1.8.0      && sudo sh autogen.sh     && sudo. Configure      && sudo make      && sudo make install      && sudo rm-rf/usr/local/src/ libuv-1.8.0      && cd ~/      && sudo ldconfig  EXPOSE 5600 entrypoint ["Dotnet", "Run"]

(2) based on Dotnet:0.0.1-alpha-onbuild

From Microsoft/dotnet:0.0.1-alpha-onbuild RUN sudo apt-get-y update     && sudo apt-get install-y dialog make AU Tomake Libtool Curl RUN Curl-ssl https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv--c/usr/local/src     && cd/usr/local/src/libuv-1.8.0     && sudo sh autogen.sh      & amp;& sudo./configure      && sudo make      && sudo make install      && sudo rm-rf/usr/loca l/src/libuv-1.8.0      && cd ~/      && sudo ldconfig  EXPOSE 5600

5.2.3 to detect if the dockerfile is working properly
Because the. NET core moment is being updated, the dotnet image update provided by the official website NET CLI Preview Docker image is not as likely to be an error when executing dotnet restore: Unknown keyword Platform (mainly dotnet image internal. NET Core and CLI versions are too old, and there are bugs) that will cause our dockefile based on it to fail. If you are unsure whether your current dotnet image has the above problem, here is a solution to the detection method and problem (1) The detection method executes the following command to load the dotnet image, and typically automatically starts Test_container and enters into the image internal environment , if you do not have dotnet image on your server, the following command will also automatically download Docker run--name test_container-it microsoft/dotnet:latest if Test_container does not start, Then execute the following command to start and associate into the Docker start Test_container dokcer attach test_container into the image internal environment
# mkdir test# cd test# git clone https://github.com/aspnet/cli-samples.git# cd cli-samples# dotnet restore

See if you have an error

Purge Test files
# CD ~# rm-r test

(2) Solutions

Manually make a dotnet image that uses the latest. NET Core SDK, or use the image sobit17/sobit-dotnet:1.0.0-beta-002252 that I've already done, but if you don't have an error, you can omit this step. Use back the original dotnet image. Create a new image here you can use the Dotnet:0.0.1-alpha as the prototype, or the dotnet :0.0.1-alpha-onbuild Loading dotnet image


If Dotnet_container is not started, execute the following command to start and associate the entry

View the. NET Core version (the Ubuntu14.04 system is used in dotnet image)

dotnet--version or dotnet--info

Since the dotnet package for Ubuntu is only up to 1.0.0-beta-00.1793, this version also has the same bug. (Find can use Apt-cache search Xx|grep xx (xx is a part of the software name you know), or you can view it from here Http://apt-mo.trafficmanager.net/repos/dotnet/pool/main /d/dotnet/) So you cannot take advantage of Apt-get upgrade dotnet or apt-get remove dotnet = 1.0.0.001598-1apt-get Install dotnet=1.0.0.002252-1 (Ub Untu not this latest version) can only download binaries from GitHub, install to the latest version (the latest version can be found on GitHub: https://github.com/dotnet/cli#installers-and-binaries)


Or
Apt-get Updatewget https://dotnetcli.blob.core.windows.net/dotnet/beta/Binaries/Latest/ DOTNET-DEV-UBUNTU-X64.LATEST.TAR.GZTAR-ZXF dotnet-dev-ubuntu-x64.latest.tar.gzln-s/dn_new/dotnet/usr/bin/dotnet

Next, execute the following command

At this point, base image is finished.

Next, just modify the Hellomvc dockerfile to specify the new image as the base image
From Dotnet_new or Sobit17/sobit-dotnet:1.0.0-beta-002252run mkdir-p/webappcopy. /webappworkdir/webapprun ["dotnet", "Restore"]# #备注: Install LIBUV This process can actually be installed in the production of dotnet_new image, you do not need this paragraph " Note You need to delete "RUN sudo apt-get-y update     && sudo apt-get install-y dialog make Automake Libtool Curl run in Dockerfile Curl-ssl https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv--c/usr/local/src     && cd/usr/local/src/libuv-1.8.0     && sudo sh autogen.sh     & amp;& sudo./configure     && sudo make     && sudo make install     && sudo rm-rf/usr/loca l/src/libuv-1.8.0     && cd ~/     && sudo ldconfigexpose 5600ENTRYPOINT ["dotnet", "Run"]

All the information that made the HELLOMVC into image is ready for completion.

5.2.4 make HELLOMVC image, the current directory is moved to HELLOMVC, execute the following command (during the production process may be due to network problems, you can repeatedly execute the following command until success is possible)
Docker build-t Hellomvc-image. Remember that the command finally had '. '

6. Compile and run Hellomvc
    • Compile trial run: Docker run--rm-w/webapp hellomvc-image
    • Run: Docker run-t--name web_container-d-P 5100:5600 hellomvc-image
Open Browser http://IP:5100 (firewall and view network related commands see 4th of this article)
Ii. Deployment in CentOS 7

1. Environment

The environment shown here is Centos7,64bit

2. Install the. NET Core SDK

Try to execute the command:. /dotnet

Prompt error:

Failed to Load/root/dotnet/bin/libcoreclr.so, Error:libunwind.so.8:cannot open Shared object file:no such file or dire Ctory

Workaround:

Yum Install-y Libunwind

Try to execute the command:. /dotnet

Prompt error:

Failed to initialize CoreCLR, hresult:0x80131500

Workaround:

Yum install-y ICU

Try to execute the command:. /dotnet--info, Normal.


Permanently save environment variables

Locate the/etc/profile file (the file is executed when the user logs on for the first time), and in the last side add:

PATH=~/DN_CLI: $PATHexport PATH is in immediate effect source/etc/profile

3. Download Cli-samples HELLOMVC Example

CD ~mkdir appcd appgit clone https://github.com/aspnet/cli-samples.gitcd cli-samplesdotnet RESTORECD HELLOMVC

You need to explicitly specify the port of HELLOMVC (even if you specify Port 5000), and now try not to add the following code, found that the default of 5000 does not work

4. Compile and run Hellomvc

Position the current directory of the executing command to HELLOMVC and execute the following command

Dotnet Run


Open Browser http://IP:5600 (firewall and view network related commands see 4th of this article)
third, run in Ubuntu 14.04  

1. Install Ubuntu installers

mkdir Dn_clicd Dn_cliwget https://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/ Dotnet-host-ubuntu-x64.latest.debwget https://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/ Dotnet-sharedframework-ubuntu-x64.latest.debwget https://dotnetcli.blob.core.windows.net/dotnet/beta/Installers /latest/dotnet-sdk-ubuntu-x64.latest.deb//Installing Dpkg-i dotnet-host-ubuntu-x64.latest.debdpkg-i Dotnet-sharedframework-ubuntu-x64.latest.debdpkg-i Dotnet-sdk-ubuntu-x64.latest.deb

2. Download Cli-samples HELLOMVC Example
CD ~mkdir appcd appgit clone https://github.com/aspnet/cli-samples.gitcd cli-samplesdotnet RESTORECD HELLOMVC

You need to explicitly specify the port of HELLOMVC (even if you specify Port 5000), and now try not to add the following code, found that the default of 5000 does not work



3. Compile and run Hellomvc
Dotnet Run
Open Browser http://IP:5600 (firewall and view network related commands see 4th of this article)

Iv. Other1, open, disable FIREWALLD and other related commands (iptables, Docker same)View Code

2, Firewall firewalld common commandsView Code

3, Firewall iptables common commandsView Code

4, some Network Port query command

View Code

Related information:

    • Running ASP. 5 Applications in Linux Containers with Docker
    • Installing ASP. NET 5 on Linux
    • Docker Dockerfile Detailed
    • ASP. NET core and ASP. DOTNET-CLI under the latest version of "RC2 early adopters"
    • ASP. NET Core 1.0 Hello World

b.it
Source: http://www.cnblogs.com/ImBit/p/5375577.html

ASP. NET Core 1.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.