Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice Needed: MSBuild task for NSwag breaks when implement Aspire.Seq #5100

Open
johnkattenhorn opened this issue Feb 2, 2025 · 1 comment

Comments

@johnkattenhorn
Copy link

Describe the bug

If I add Aspire SEQ integration the MSBuild task breaks with the following exception:

NSwag command line tool for .NET Core Net90, toolchain v14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0));Visit http://NSwag.org for more information.;NSwag bin directory: C:\Users\JohnKattenhorn.nuget\packages\nswag.msbuild\14.2.0\tools\Net90;Executing file 'config.nswag' with variables 'Configuration=Debug'...;Launcher directory: C:\Users\JohnKattenhorn.nuget\packages\nswag.msbuild\14.2.0\tools\Net90;System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.; ---> System.InvalidOperationException: NSwag requires the assembly Applicita.TestApp.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null to have either an BuildWebHost or CreateWebHostBuilder/CreateHostBuilder method

This is caused by these lines of code in the Aspire.Seq extension because at BuildTime the settings.ServerUrl is null (its populated during runtime), I'm guessing the NSwag build task is executing this code.

 if (!settings.DisableHealthChecks)
 {
     if (settings.ServerUrl is not null)
     {
         builder.TryAddHealthCheck(new HealthCheckRegistration(
             "Seq",
             _ => new SeqHealthCheck(settings.ServerUrl),
             failureStatus: default,
             tags: default));
     }
     else
     {
         throw new InvalidOperationException(
             "Unable to add a Seq health check because the 'ServerUrl' setting is missing.");
     }
 }

Version used

14.2

To Reproduce

Create a Aspire Starter app from the Visual Studio 2022, Add Seq as per the documentation here. (https://learn.microsoft.com/en-us/dotnet/aspire/logging/seq-integration?tabs=dotnet-cli), try to build the solution.

Expected behavior

The build should be completed successfully.

Additional context

I've workaround this by bringing the source code for Aspire into my solution and commenting out the source code.

Adding this line to the appsetting.config also fixes the issue but is not desired as configuration is being done in code:

  "Aspire": {
    "Seq": {
      "ServerUrl": "http://localhost:5341"
    }
  }

I've also logged an issue for awareness on the Aspire Site, any workarounds or thoughts about what the Aspire Code should look like or modification to the NSwag configuration would be appreciated.

@johnkattenhorn
Copy link
Author

My issue affects more that Seq, it's also having problems with EF and Migrations. I'm still looking at the MSBuild Task documentation but it's seems to be that operates on the assumption that all configuration is being done statically at runtime.

It's almost like it needs to start the Aspire Runtime before it starts the documentation generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant