Search code examples
c#asp.net-mvc-3migrationmigratordotnet

MigratorDotNet: No public classes with the Migration attribute were found


Got next execption trying to applay migration using MigratorDotNet:

No public classes with the Migration attribute were found

Build secceded in general, no config error appear.

I have build config file with next content:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectRoot Condition="'$(ProjectRoot)' == ''">$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</ProjectRoot>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <ClassLibraryOutputDirectory>bin\$(Configuration)</ClassLibraryOutputDirectory>
        <MigrationsProject>$(ProjectRoot)\Solution\SqlMigrator\SqlMigrator.csproj</MigrationsProject>
    </PropertyGroup>

    <Import Project="Migrator.Targets" />

    <Target Name="Build-Migrations">
        <MSBuild Projects="$(MigrationsProject)" Targets="Build">
            <Output TaskParameter="TargetOutputs" ItemName="MigrationAssemblies" />
        </MSBuild>

        <Message Text="Built: @(MigrationAssemblies)"/>
    </Target>

    <Target Name="Migrate" DependsOnTargets="Build-Migrations">
        <Message Text="Migrating: @(MigrationAssemblies)"/>
        <Migrate Provider="MySql"
            Connectionstring="server=localhost;User Id=root;password=;database=loveproject"
            Migrations="@(MigrationAssemblies)" />
    </Target>
</Project>

I have one test migration:

namespace SqlMigrator
{
    using Migrator.Framework;
    using System.Data;

    [Migration(20140401110402)]
    public class TestMigrate : Migration
    {
        public override void Up()
        {
            this.Database.ExecuteNonQuery(@"CREATE TABLE example (id INT, data VARCHAR(100));");
        }

        public override void Down()
        {

        }
    }
}

Execution of migration: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe mbuild.proj /t:Migrate


Solution

  • Found the problem. The issue was in version of Migrator inside Project and that i call from msbuild.

    I installed the latest version from Nuget and download executables from web side to build in into msbuild (Migrator.MSBuild.dll). It was 2 otehr versions used in my project and in msbuild script.