Particular / NServiceBus.Persistence.Sql

Native SQL Persistence for NServiceBus
https://docs.particular.net/persistence/sql/
Other
36 stars 27 forks source link

Controlling SqlPersistence scripts generation is unnecessarily complex #983

Open mauroservienti opened 5 years ago

mauroservienti commented 5 years ago

SqlPersistence offers an option to control scripts generation via an assembly level attribute. When using the attribute it seems natural to disable scripts generation byu setting values to false:

[assembly: SqlPersistenceSettings(
    MsSqlServerScripts = false,
    MySqlScripts = false,
    OracleScripts = false,
    PostgreSqlScripts = false,
    ProduceOutboxScripts = false,
    ProduceSagaScripts = false,
    ProduceSubscriptionScripts = false,
    ProduceTimeoutScripts = false)]

When all values are set to false the expected behavior is that the script generation is disabled. That's not the case, build fails with the following non-guiding error:

SqlPersistenceTask: Must define at least one of MsSqlServerScripts, MySqlScripts, OracleScripts, or PostgreSqlScripts. Add a [SqlPersistenceSettingsAttribute] to the assembly

The solution is to disable script generation using MSBuild:

<PropertyGroup>
    <SqlPersistenceGenerateScripts>false</SqlPersistenceGenerateScripts>
</PropertyGroup>

I fail to see why that's needed, or at least I'd expect a much more guiding error.

bording commented 5 years ago

@mauroservienti The reason the MSBuild setting was added is that it prevents the script generation targets from running and the task assembly from even being loaded at all during compile time.

Examining the attribute to know not to run script generation means the script generation code needs to run first.

mauroservienti commented 5 years ago

Thanks @bording. I guess a better approach could be: