Update 2: The file does not get published. That is what is wrong. However, I can't figure out why one of my computers can publish it the right way and the other doesn't after the Visual studio upgrade.
Update: Running the same solution on two different computers where the APIProject.xml file get's correctly published from one computer but not the other there are now only one difference left. The computer from which the publishing works runs the not updated version of Visual studio 2017 Enterprise. 15.5.2 does not work and 15.4.2 works.
I'm getting this error:
FileNotFoundException: Could not find file 'D:\home\site\wwwroot\APIProject.xml'.
The file is placed in bin\Debug\netcoreapp2.0 It works locally but when published to Azure App service it crashes.
I'm publishing to the staging slot I created and haven't tried production yet. Publishing replaces all files at destination.
Here is my setup of Swagger but it used to work :)
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);
});
}
What has changed is I added the "UseSetting"-row in Program.cs to get errors of why it doesn't start. Before adding that row I did't get developer error, only got end user error page.
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
.UseStartup<Startup>()
.Build();
I'm trying to publish with Debug mode. Also tried with Release as of one answer below but no difference.
I checked out the code in another computer and publishing from that computer works so the problem just got more weird to me!
Add and configure Swagger middlewareLaunch the app and navigate to https://localhost:<port>/swagger/v1/swagger.json . The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .
Open your project in Visual Studio. In Solution Explorer, right-click the Connected Services node, and, from the context menu, select Add Connected Service. In the Connected Services tab, select the + icon for Service Dependencies. In the Add Dependency page, select Azure App Configuration.
My .Net Core 2.0 app worked fine locally, but threw a pointless "An error occurred while starting the application." error when deployed to Azure.
Checking the logs, the cause was that Swagger couldn't find a particular .xml file (why the hell doesn't the error message let us know ?!)
The solution was to select the Build tab, change the Configuration drop down list to "Release", then tick this box:
That's it.
For some reason, by default it was ticked (with the .xml filename filled in) for Debug, but not for Release.
(Sigh.)
Make sure that the equivalent block exists in the csproj file in the Debug as well as the Release mode. I guess you are publishing the release mode.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netcoreapp2.0\APIProject.xml</DocumentationFile>
</PropertyGroup>
I faced the same issue today when published ASP.NET Core Web Application powered by .NET Core 2.1 to Azure App Service.
It worked locally fine when running in Debug mode, but failed in Release. The reason was because I didn’t have the following config section in the *.csproj
file.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netcoreapp2.1\OneGit.Api.xml</DocumentationFile>
</PropertyGroup>
...
</Project>
Which is represent the checkbox XML documentation file
in the section Build
=> Output
when right-click on a project and select menu-item Properties
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With