Development environment: WIN10
Development tools: Visual Studio 2015
Deployment environment: CentOS 7-x64 or MacOS 10.12
First, the preparatory work
(i) Development of machinery
1. Install VS2015. NET Core Development tools: Visual Studio Tools (Preview 2),: https://go.microsoft.com/fwlink/?LinkId=827546;
2. Install. NET Core sdk,:https://go.microsoft.com/fwlink/?linkid=835009;
3. The ASP. NET Core program can start the Web service using the command line, and if you need to use IIS, also download a server: Windows Server hosting,:https://aka.ms/dotnetcore_windowshosting_1_1_0
(ii) Deployment of machinery
1. Install the. NET Core Environment
(1) CentOS installation method see: Https://www.microsoft.com/net/core#linuxcentos;
(2) MacOS installation method See: Https://www.microsoft.com/net/core#macos
2. Installing Nginx
(1) CentOS installation method see: http://blog.csdn.net/renminzdb/article/details/48948165;
(2) MacOS Installation method: Enter in Terminal " brew install nginx”,
after installation is complete, enter" to nginx -v”
see if the installation was successful.
Second, the development
(i) new. Net Core Program
(ii) Modification of the Project.json document
1. Comment out the phrase "type"
1 "dependencies": { 2 "Microsoft.NETCore.App": { 3 "version": "1.0.0" 4 //"type": "Platform" 5 }
2. Comment out the phrase "postpublish"
1 "scripts": { 2 "prepublish": ["Bower Install", " dotnet bundle"] 3 //" Postpublish ": [" dotnet Publish-iis--publish-folder%publish:o utputpath%--framework%publish:fulltargetframework% "] 4 }
3. Add "Runtimes" to the platform you want to publish.
1"Scripts": {2"Prepublish": [ "Bower Install", "dotnet Bundle" ]3 //"Postpublish": ["dotnet publish-iis--publish-folder%publish:outputpath%--framework%publish: fulltargetframework% "]4},5"runtimes": {6"centos.7-x64": {},7"osx.10.10-x64": {},8"win10-x64": {},9"win8-x64": {},Ten"win81-x64": {} One}
(iii) Publication
1. Open cmd, enter the program directory "src\ project name", execute "donnet restore";
2. Execute "dotnet publish–r centos.7-x64", if MacOS is "dotnet publish–r osx.10.10-x64" (MacOS 10.12 test is also available);
3. Copy the "Src\ Project name \bin\debug\netcoreapp1.0\centos.7-x64" to the CentOS or MacOS machine.
III. deployment
(i) running the program
1. Run "terminal", enter the program directory, enter the "dotnet Program entry file name:. dll" (such as "dotnet WebApp1.dll" or "dotnet ConsoleApp1.dll", etc.), the current window does not close;
2. If it is an ASP. NET Core program, enter the URL (such as http://localhost:5000) to see if the service has started properly.
(ii) Configuring Nginx Proxy
1. MacOS Configuration:
After installing Nginx, the default profile path is in the /usr/local/etc/nginx
folder. Locate the nginx.conf configuration file in this folder, open it using Visual Studio Code, and in the Server
node, locate the location node that listens on port 80, and modify the configuration as follows:
1server {2Listen 80;3 4#root/usr/share/nginx/html;5#index index.html index.htm;6 7# make site accessible from http://localhost/8server_name localhost;9 TenLocation/{ OneProxy_pass http://localhost:5000; AProxy_http_version 1.1; -Proxy_set_header Upgrade $http _upgrade; -Proxy_set_header Connection keep-alive; theProxy_set_header Host $host; -Proxy_cache_bypass $http _upgrade; -} -}
Save and exit, and then use the sudo nginx -s reload
command to reload the configuration.
Then we open the browser input http://localhost, found at this time through Nginx to visit our site.
2. CentOS Configuration:
After installing Nginx, the default configuration file path is in the /etc/nginx/sites-available/default
file. Switch working directory to /etc/nginx/sites-available/
, use the sudo gedit default
command to open the default file.
The follow-up action is the same as the MacOS operation above.
Deploy. NET core programs across platforms