cake-contrib / Cake.FluentMigrator

FluentMigrator task for Cake
https://cakebuild.net/extensions/cake-fluentmigrator/
MIT License
6 stars 14 forks source link

FluentMigrator function not found issue in Cake.FluentMigrator #27

Open shailesh1984 opened 2 years ago

shailesh1984 commented 2 years ago

Hi Team,

I am getting "FluentMigrator" not found an issue in the build cake script. I have used the below code.

Code:

tool nuget:?package=Cake.FluentMigrator&version=0.4.0

..... Task("Run-DbMigration") .IsDependentOn("Build") .Does(() => { FluentMigrator(new FluentMigratorSettings{ Connection = connectionstring, Provider= "sqlserver", Assembly = migrationdll }); }); ......

Versions : Cake.Core - 2.2.0 (latest) Cake.FluentMigrator - 0.4.0

Please help me on this issue.

Thanks, Shailesh M

nils-a commented 2 years ago

The underlying problem would be #28. Try using Cake 0.38.5 (i.e. the last version before Cake 1.0.0 - which is mentioned in #24)

shailesh1984 commented 2 years ago

I have downgraded the Cake version from 2.2.0 to 0.38.5, but still, I am getting the same issue. Please let me know if I have done any mistakes in this code and I have attached the image of my folder structure with the error.

  1. dotnet-tools.json :
{
  "version": 1,
  "isRoot": true,
  "tools": {
    "cake.tool": {
      "version": "0.38.5",
      "commands": [
        "dotnet-cake"
      ]
    }
  }
}
  1. build.cake :
#tool nuget:?package=Cake.FluentMigrator&version=0.4.0

var target = Argument("target", "DbMirgration");
var configuration = Argument("configuration", "Release");

var solutionpath = "./";
var outputPath = "./Artifacts";
var dbConnection = "Data Source=.;Initial Catalog=DbMigration;integrated security=true";

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task("Clean")
    .WithCriteria(c => HasArgument("rebuild"))
    .Does(() =>
{
    CleanDirectory(solutionpath);
});

Task("Build")
    .IsDependentOn("Clean")
    .Does(() =>
{
    DotNetCoreBuild(solutionpath, new DotNetCoreBuildSettings
    {
        Configuration = configuration,
    });
});

/*Task("Test")
    .IsDependentOn("Build")
    .Does(() =>
{
    DotNetCoreTest(solutionpath, new DotNetCoreTestSettings
    {
        Configuration = configuration,
        NoBuild = true,
    });
});*/

Task("Publish")
    .IsDependentOn("Build")
    .Does(() =>
{
    DotNetCorePublish(solutionpath, new DotNetCorePublishSettings
    {
        Configuration = configuration,
        NoBuild = true,
        OutputDirectory = outputPath
    });
});

Task("DbMirgration")
    .IsDependentOn("Publish")
    .Does(() =>
{
    FluentMigrator(new FluentMigratorSettings{
        Connection = dbConnection,
        Provider= "sqlserver",
        Assembly = "./Artifacts/CakeBuild.FluentMigration.dll"
    });
});

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);

image

nils-a commented 2 years ago

@shailesh1984 there are a bunch of things at play here, most are related of Cake.FluentMigrator being kind of "old" (Or rather 'not updated in a long time'.)

Cake Runner

Cake.FluentMigrator ships only a net461 library. So there is no way to use it using the .NET tool. You need to use the full fat Framework runner of Cake. (Which was removed in version 2.0.0)

For this, it would be easiest if you used the build.ps1 from the resources-repo.

24 and/or #28 should fix this problem in due time.

tools and addins

There is a slight "error" in your cake-file: Cake.FluentMigrator is an addin, so it needs to be loaded using the #addin directive, not #tool.

The first line of your cake file should read

#addin nuget:?package=Cake.FluentMigrator&version=0.4.0

But the Migrate.exe is still needed, so you'll need a #tool, as well:

Version of FluentMigrator

Cake.FluentMigrator is searching for a very specific path which was lastly available in the (deprecated) FluentMigrator.Tools in version 1.6.2. (#29 should fix this problem.)

Hence, the first lines of your script need to look like:

#addin nuget:?package=Cake.FluentMigrator&version=0.4.0
#tool nuget:?package=FluentMigrator.Tools&version=1.6.2

Hope this helps.