将以下内容添加到您的 .csproj 文件中:
<UsingTask TaskName="FluentMigrator.MSBuild.Migrate" AssemblyFile="$(MSBuildProjectDirectory)\FluentMigrator.MSBuild.dll" />
<Target Name="Migrate">
<Message Text="Migrating database" />
<Migrate Database="sqlserver" Connection="YOUR CONNECTION STRING" Target="$(IntermediateOutputPath)YOUR DLL NAME.dll">
</Migrate>
</Target>
还要确保在 Build 目标之后添加目标,如下所示:
<Project ToolsVersion="4.0" DefaultTargets="Build;Migrate;Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
您可能已经注意到我从项目目录中加载了 msbuild 任务。我将FluentMigrator.MSBuild.dll 和 FluentMigrator.Runner.dll程序集复制到我的项目文件夹中。当我尝试从包文件夹加载程序集时,我收到一条错误消息,指出程序集的格式不正确......