没有找到带有Migration属性的公共类
本文关键字:属性 Migration | 更新日期: 2023-09-27 18:06:33
尝试使用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。项目/t:迁移
找到问题。这个问题是在项目内部的Migrator版本,我从msbuild调用。
我从Nuget安装了最新版本,并从web端下载了可执行文件,以构建到msbuild (Migrator.MSBuild.dll)中。在我的项目和msbuild脚本中使用了另外两个版本。