用 dotnet run 命令运行 asp.net core 程序出现下面的错误:
/git/AboutUs/Program.cs(14,26): error CS1061: 'IWebHostBuilder' does not contain a definition for 'UseApplicationBasePath' and no extension method 'UseApplicationBasePath' accepting a first argument of type 'IWebHostBuilder' could be found (are you missing a using directive or an assembly reference?)
Program.cs 的代码如下:
public class Program { public static void Main(string[] args) { var host = new WebHostBuilder() .UseServer("Microsoft.AspNetCore.Server.Kestrel") .UseUrls("http://*:8001") .UseApplicationBasePath(Directory.GetCurrentDirectory()) .UseDefaultConfiguration(args) .UseIISPlatformHandlerUrl() .UseStartup<Startup>() .Build(); host.Run(); } }
之前是能正常运行的。
原来是 Microsoft.AspNetCore.Hosting 的 API 改了,UseApplicationBasePath() 被改名为 UseContentRoot() 。
Microsoft.AspNetCore.Hosting又改名了:.UseDefaultConfiguration() 改为了 .UseDefaultHostingConfiguration()