得到下一个执行尝试使用 MigratorDotNet 应用迁移:
No public classes with the Migration attribute were found
构建一般,没有出现配置错误。
我已经构建了包含下一个内容的配置文件:
<?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>
我有一个测试迁移:
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()
{
}
}
}
执行迁移:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe mbuild.proj /t:Migrate