SQL installation scripts are created as compile-time outputs alongside a project's binary outputs. These scripts can be promoted to a directory under source control so that differences can be tracked and analyzed.
Scripts will be created in the directory format of [CurrentProjectDebugDir]\
.
For example, for a project named ClassLibrary
built in Debug mode, the following directories will be created.
ClassLibrary\
bin\ Debug\ NServiceBus. Persistence. Sql\ MsSqlServer ClassLibrary\
bin\ Debug\ NServiceBus. Persistence. Sql\ MySql ClassLibrary\
bin\ Debug\ NServiceBus. Persistence. Sql\ Oracle ClassLibrary\
bin\ Debug\ NServiceBus. Persistence. Sql\ PostgreSql
Scripts will also be included in the list of project output files. This means that those files produced will be copied to the output directory of any project that references it.
Projects using
project.json
are not supported. The project.json
approach was an experiment by Microsoft for a new project system that was not based on MSBuild. Since project.json
did not support running MSBuild files shipped inside a NuGet, the SQL Persistence script creation does not work. This experiment has since been abandoned. To fix this, either migrate back to the older Visual Studio 2015 project format (.csproj
and packages.config
) or migrate to the new Visual Studio 2017 project format. dotnet-migrate can help migrating to the new .csproj
format.SqlPersistenceSettings attribute
Scripts creation is configured via [SqlPersistenceSettings]
applied to the target assembly.
To produce all scripts
[assembly: SqlPersistenceSettings(
msSqlServerScripts: true,
mySqlScripts: true)]
To produce only MS SQL Server scripts
[assembly: SqlPersistenceSettings(msSqlServerScripts: true)]
To produce only MySQL scripts
[assembly: SqlPersistenceSettings(mySqlScripts: true)]