NServiceBus.Persistence.Sql
NServiceBus.Persistence.Sql copied to clipboard
Investigate if it's possible to generate SQL scripts using Roslyn source generators
Script generation currently has several limitations given that it uses Mono.Cecil to analyze code for saga definitions as an MSBuild step. By using Roslyn source generators the generation would happen direclty during the compile, likely with more metadata available as a part of being more tightly coupled to the compilation.
It may not be possible to create SQL scripts directly through a source generator, but even if this is the case the source generator could create a well known static method in the compiled output with hardcoded metadata hardcoded from the sagas that were compiled. The scripts themselves could be created by executing the dotnet tool, which would load the endpoint assembly and execute the well known method with a specific path.
This would require at least the Roslyn 3 SDK, which would limit this functionality to Visual Studio 2019, and to use incremental generators (which would be recommended for compile performance) would require the Roslyn 4 SDK, which means Visual Studio 2022. However starting in Visual Studio 2022 there are limited ways to multitarget analyzers, and provide a fallback analyzer version for Visual Studio 2019. In any case, this likely means that changing to a Roslyn-based generation system would require a new major version of SQL Persistence.