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
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.
We have also prepared a git repo for reproduction.
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
.props files that ship with each of those dependencies.
In the Receiver project, if you change your package reference like this, however:
<PackageReference Include="NServiceBus.Persistence.Sql" Version="7.0.4" PrivateAssets="build;buildTransitive" />
PrivateAssets value makes the things in the
buildTransitive directories in the NuGet package apply only to the local project and not get shipped up the chain.
The documentation for all this, by the way, is here:
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.
Thanks @DavidBoike , @bording.
PrivateAssets="build;buildTransitive" does it for us.
We will keep this in mind with the Directory.Build.props option, will be handy at one stage.