We ran into unexpected behaviour with the NServiceBus SQL script generation.
Our end goal is to not generate any NSB SQL scripts when building our solution. Can we please get support on how we can achieve this?
What we observed are:
Building a project with a direct or transitive reference to a project with NSB references results in the generation of SQL scripts for all dialects in the output of the trigger project.
What we configured (.NET6):
The NSB project has the <SqlPersistenceGenerateScripts>false</SqlPersistenceGenerateScripts>.
No SQL scripts are generated when building the NSB project, and this is expected.
A new project is set with a reference to the NSB project.
SQL scripts for all dialects are generated in the bin when building the project.
This is an artifact of how MSBuild works. Each project is built independently, and because SQL Persistence is a transitive reference, by default it inherits the .targets and .props files that ship with each of those dependencies.
In the Receiver project, if you change your package reference like this, however:
The PrivateAssets value makes the things in the build and buildTransitive directories in the NuGet package apply only to the local project and not get shipped up the chain.
Another option to control this behavior would be to set <SqlPersistenceGenerateScripts>false</SqlPersistenceGenerateScripts> in a Directory.Build.props file located next to the solution file.
That would ensure that it is disabled for every project. Once you’ve done that, for any project that you might want to have script generation enabled, you would add <SqlPersistenceGenerateScripts>true</SqlPersistenceGenerateScripts> to that project file.