Skip to content

MSBuild Runner Options

Daniel Lee edited this page May 5, 2013 · 5 revisions

The MSBuild task for FluentMigrator is a way to run migrations from MSBuild build scripts and is very similar to the Command Line Runner Options and Nant Runner Options. Some options have multiple names e.g. Database or DatabaseType

Example:


<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Migrate">	
   <UsingTask TaskName="FluentMigrator.MSBuild.Migrate" 
        AssemblyFile="./lib/FluentMigrator.MSBuild.dll"/>

  <Target Name="Migrate" >
    <Message Text="Starting FluentMigrator Migration"/>
    <Migrate Database="sqlserver2008"
             Connection="server=.\SQLEXPRESS;uid=testfm;pwd=test;Trusted_Connection=yes;database=FluentMigrator"
             Target="./Migrations/bin/Debug/Migrations.dll" 
             Output="True"
             OutputFilename="generated.sql">
    </Migrate>
  </Target>
  
  <Target Name="MigrateRollbackAll" >
    <Message Text="Starting FluentMigrator Rollback All"/>
    <Migrate Database="sqlserver2008"
             Connection="server=.\SQLEXPRESS;uid=testfm;pwd=test;Trusted_Connection=yes;database=FluentMigrator"
             Target="./Migrations/bin/Debug/Migrations.dll"
	     Task="rollback:all">
    </Migrate>
  </Target>

</Project>

Target, MigrationAssembly (required)

The path to the assembly containing the migrations you want to execute.

Database, DatabaseType (required)

The kind of database you are migrating against. Available choices are:

  • sqlserver2000
  • sqlserver2005
  • sqlserver2008
  • sqlserver2012
  • sqlserverce
  • sqlserver
  • mysql
  • postgres
  • oracle
  • sqlite
  • jet

Connection (required)

The connection string to the server and database you want to execute your migrations against. This can be a full connection string or the name of the connection string stored in a config file.

When specifying a named connection string, FluentMigrator searchs for it in this order:

1. The specified config file via --connectionStringConfigPath parameter
2. Target assembly’s config file
3. Machine.config config file

ConnectionStringConfigPath (optional)

The path of the config file where the connection string named by is found. If not specified, it defaults to lookup order specified --connectionString parameter documentation

Task (optional)

The task you want FluentMigrator to perform. Available choices are:

  • migrate:up
  • migrate (same as migrate:up)
  • migrate:down
  • rollback
  • rollback:toversion
  • rollback:all
  • listmigrations

Default is ‘migrate’.

Verbose (optional)

Show the SQL statements generated and execution time in the console. Default is false. This is a boolean switch so it can be set to "True" or "False".

Output (optional)

Output generated SQL to a file. Default is no output. Use outputFilename to control the filename, otherwise [assemblyname].sql is the default. This is a boolean switch so it can be set to "True" or "False".

OutputFilename (optional)

The name of the file to output the generated SQL to. The output option must be included for output to be saved to the file. The file will be placed in the same directory as the MSBuild script was executed from.

Namespace (optional)

The namespace contains the migrations you want to run. Default is all migrations found within the Target Assembly will be run.

Nested (optional)

Whether migrations in nested namespaces should be included. Used in conjunction with the namespace option. This is a boolean switch so it can be set to "True" or "False".

Steps (optional)

The number of versions to rollback if the task is ‘rollback’. Default is 1.

PreviewOnly (optional)

Only output the SQL generated by the migration – do not execute it. Default is false. This is a boolean switch so it can be set to "True" or "False".

Version (optional)

The specific version to migrate. Default is 0, which will run all migrations.

Profile (optional)

The profile to run after executing migrations.

Timeout (optional)

Overrides the default SqlCommand timeout of 30 seconds.

WorkingDirectory (optional)

The directory to load SQL scripts specified by migrations from.

Tags (optional)

Filters migrations to be run based on tags. See Filter migrations run based on Tags

ApplicationContext (optional)

A string argument that can be used in a migration. See ApplicationContext: Passing parameters to Migrations

TransactionPerSession (optional)

The default transaction is one transaction per migration so the default for this switch is false. Run migrations in one transaction per session (task) instead. This is a boolean switch so it does not take a value. It can be set to "True" or "False".

Clone this wiki locally