I've added this rows to my .csproj file
<Target Name="SwaggerPostBuildTarget" AfterTargets="PostBuildEvent">
<Exec Command="dotnet tool restore"></Exec>
<Exec Command="dotnet tool install Swashbuckle.AspNetCore.Cli --version 6.4.0"></Exec>
<Exec Command="dotnet swagger tofile --output swagger/v1/swagger.json $(OutputPath)$(AssemblyName).dll v1"></Exec>
<Exec Command="dotnet swagger tofile --output swagger/v2/swagger.json $(OutputPath)$(AssemblyName).dll v2"></Exec>
<Exec Command="dotnet swagger tofile --output swagger/v3/swagger.json $(OutputPath)$(AssemblyName).dll v3"></Exec>
</Target>
when I run the project I get this error:
MSB3073 - The command "dotnet swagger tofile --output /swagger/v1/swagger.json bin\Debug\net6.0\xxx.dll v1" exited with code -532462766
I followed step by step the instructions in https://github.com/domaindrivendev/Swashbuckle.AspNetCore#swashbuckleaspnetcorecli but it is not working.
Any ideas on what this error means?
UPDATE
With more tries I understood that while executing the post build command the environment variables are not yet set and this is what is causing my error, since I try to read an environment variable. This is my launchsettings.json:
This is the output of my execution:
What I also notice is that the port on which is listening are not the ones I set, but I can't understand from where they are read
UPDATE 2
I found this: How to get Environment Variable in csproj file? but it is not working and I can't neither get clarification since I cannot comment yet. Also there is this issue on github https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2290 that explain why I'm getting this errors, but still I'm not able to build the project without errors
UPDATE 3 I have been able to generate the json files. Now the instructions in my csproj file looks like this: and my Program.cs file is:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Custom configurations
var startup = new Startup(builder.Configuration);
startup.ConfigureServices(builder.Services);
var app = builder.Build();
startup.Configure(app, app.Environment, app.Services.GetRequiredService<IApiVersionDescriptionProvider>());
app.Run();
<Exec Command="if exist swagger rd /q /s swagger"></Exec> <Exec Command="mkdir swagger"></Exec> <Exec Command="mkdir swagger\v1"></Exec> <Exec Command="dotnet swagger tofile --output swagger/v1/swagger.json $(OutputPath)$(AssemblyName).dll v1"></Exec>
– Lent