更新2:该文件不会被发布。这就是问题所在。但是,我不明白为什么我的一台计算机可以以正确的方式发布它,而另一台计算机在 Visual Studio 升级后却不能。
Update:在两台不同的计算机上运行相同的解决方案,其中一台计算机可以正确发布 APIProject.xml 文件,但另一台计算机不能正确发布,现在只剩下一个区别了。进行发布的计算机运行未更新版本的 Visual studio 2017 Enterprise。 15.5.2 不起作用,15.4.2 起作用。
我收到此错误:
FileNotFoundException:找不到文件
'D:\home\site\wwwroot\APIProject.xml'。
文件放置在bin\Debug\netcoreapp2.0
它可以在本地运行,但是当发布到 Azure 应用服务时它会崩溃。
我正在发布到我创建的暂存槽,但尚未尝试生产。发布将替换目标处的所有文件。
这是我的 Swagger 设置,但它曾经有效:)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "Ecommerce/Product API",
Description = "Handles API based shopping functionality",
TermsOfService = "Terms of service should be contracted with inidividually",
Contact = new Contact { Name = "Magnus", Email = "magnus@secret", Url = "" },
License = new License { Name = "Use under permission from our Group", Url = "http://aboutno" }
});
// Set the comments path for the Swagger JSON and UI.
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, "APIProject.xml");
c.IncludeXmlComments(xmlPath);
});
}
发生的变化是我在 Program.cs 中添加了“UseSetting”行以获取有关其无法启动原因的错误。在添加该行之前,我没有收到开发人员错误,只收到最终用户错误页面。
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
.UseStartup<Startup>()
.Build();
我正在尝试使用调试模式发布。还尝试使用 Release 作为下面的一个答案,但没有区别。
我检查了另一台计算机中的代码并从该计算机上进行了发布,因此问题对我来说变得更加奇怪!