0
得到下一execption嘗試使用MigratorDotNet到applay遷移:MigratorDotNet:沒有公共課與遷移屬性被發現
No public classes with the Migration attribute were found
構建一般secceded,則不會出現配置錯誤。
我建立配置文件與一個內容:
<?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 /噸:遷移
你肯定對建設與移民類定義相同的程序集? – Rup
說實話,我完全不確定我是這麼做的。這是我第一次使用msbuild腳本和migratordotnet。 :) –