Program.cs代碼以下:json
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseUrls("http://192.168.3.162:6600") .UseStartup<Startup>(); } }
命令行cmd進入發佈目錄輸入命令:api
dotnet myapi.dll
Program.cs代碼以下:ui
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build()) .UseStartup<Startup>(); } }
命令行cmd進入發佈目錄輸入命令:url
dotnet myapi.dll --server.urls "http://192.168.3.185:7100"
Program.cs代碼以下:spa
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseConfiguration(new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("hosting.json", optional: true).Build()) .UseStartup<Startup>(); } }
項目添加"hosting.json "文件,代碼以下:命令行
{ "server.urls": "http://192.168.3.185:8800" }
命令行cmd進入發佈目錄輸入命令:3d
dotnet myapi.dll
精心準備,轉載請留下原文地址。code