SQL installation scripts are created as a compile-time output alongside a project's binary outputs. Additionally, these scripts can be promoted to a directory under source control so that differences can be tracked and analyzed.
For example for a project named
ClassLibrary built in Debug mode the following directories will be created.
bin\ Debug\ NServiceBus. Persistence. Sql\ MsSqlServer
bin\ Debug\ NServiceBus. Persistence. Sql\ MySql
bin\ Debug\ NServiceBus. Persistence. Sql\ Oracle
bin\ Debug\ NServiceBus. Persistence. Sql\ PostgreSql
Scripts will also be included in the list of project output files. This means those files produced will be copied to the output directory of any project that references it.
project.are not supported. The
project.approach was an experiment by Microsoft for a new project system that was not based on MSBuild. Since
project.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 old Visual Studio 2015 project format (
packages.) or migrate to the new Visual Studio 2017 project format. dotnet-migrate can help migrating to the new
Scripts creation can configured via
[SqlPersistenceSettings] applied to the target assembly.
[assembly: SqlPersistenceSettings( MsSqlServerScripts = true, MySqlScripts = true, OracleScripts = true)]
[assembly: SqlPersistenceSettings(MsSqlServerScripts = true)]
[assembly: SqlPersistenceSettings(MySqlScripts = true)]
[assembly: SqlPersistenceSettings(OracleScripts = true)]
As stated above, scripts are created in the target project output directory. This directory will usually be excluded from source control. To ensure the scripts are added to source control, they can be promoted to a location outside the build directory.
Some token replacement using MSBuild variables is supported.
$(SolutionDir): The directory of the solution.
$(ProjectDir): The directory of the project
All tokens are drive + path and include the trailing backslash
[assembly: SqlPersistenceSettings( ScriptPromotionPath = "$(SolutionDir)PromotedSqlScripts")]
The path calculation is performed relative to the current project directory. So, for example, a value of
PromotedSqlScripts (with no tokens) would evaluate as