2

I currently have two projects:

1. ASP.NET Core 3.1 Web API + Xamarin

I am using NSwag to automatically generate the C# client in the first project. This is done using an MSBuild target which generates code into a C# Client project. This client project is then used by Xamarin. This works! (Very good! Thanks to Rico Suter for NSwag!)

I currently have my Xamarin project in a separate solution. The client library is pushed to a NuGet feed and then consumed by the Xamarin application. So they are separated. Using this flow makes the usage in the daily workflow very easy.

2. ASP.NET Core 5 Web API + Blazor WebAssembly (Hosted in WebAPI)

Now I started another project and decided to go for an easy to use application (api + frontend shipped from the server - easier to setup). Therefore I made use of the Blazor WASM (ASP.NET Core Hosted) template in Visual Studio. I decided that having the web client (blazor) in the same solution is an acceptable solution regarding debugging and the fact that they are also shipped together. This works like so: The WebAPI project has a reference to the Blazor project to be able to copy it's compiled output during compilation and include it in the WebAPI project. Another library (referenced by the webAPI and using a middleware from that library) then serves the files from this directory which enables me to serve both the api and the frontend static files from my web api project. Blazor is written in C# and therefore compiled.

Introduction to my problem: I want to use the same approach as in the first project. Except the frontend won't consume the NuGet library. Instead it should directly consume the client project. Any optional client in the future then can still consume the NuGet client library.

Now really for my problem: The reference from the webapi to the blazor project is a problem. The NSwag.MSBuild can't work on the compiled output from the web api to generate the client because the blazor project is not yet compiled (as mentioned it's a dependency). The Blazor project is not yet compiled because it does not have the updated client yet.

What I considered: Kind of work around it by decoupling some parts and having to build twice for one real build (generate client + real build). Decoupling includes removing NSwag.MSBuild. The workflow would then be:

  1. Run the project (web api)
  2. Use NSwag Studio with the locally served Swaggerfile to manually regenerate the client
  3. Stop project
  4. Restart project to make blazor to pick up the new changes in the client
  5. Now you got the real build

Do some of you have an idea on how to have a clean solution? The current one is kind of loophole. Am I overseeing something? Having to build a project twice to really start debugging seems wrong to me.

hyvte
  • 153
  • 1
  • 10

0 Answers0