Fluentmigrator: Execute.EmbeddedScript Error: Could not find resource

Created on 15 Jul 2016  Â·  11Comments  Â·  Source: fluentmigrator/fluentmigrator

Hi,

I could not run sql script in asp.net mvc c# in the following context:
How do I assign value inside EmbeddedScript ?
Below i have attempted various values but failed, the result is the same. the error is:
Could not find resource named 201607150000_ERPDomainDB_Initial.sql in assemblies ERPCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
What is the reason ?
public class _201607150000_ERPDomainDB_Initial : Migration
{
public override void Up()
{
IfDatabase("SqlServer")
.Execute.EmbeddedScript("201607150000_ERPDomainDB_Initial.sql");
//IfDatabase("SqlServer")
// .Execute.EmbeddedScript("Database.Migrations.201607150000_ERPDomainDB_Initial.sql");
}

}

}

Please help.

Thanks
itw2016

Most helpful comment

@mabead Just add .For.EmbeddedResources() to the ScanIn.

All 11 comments

My colleague changed to use this:
IfDatabase("SqlServer")
.Execute.Script(AppDomain.CurrentDomain.BaseDirectory + "\Database\Migrations\201607150000_ERPDomainDB_Initial.sql");
It's ok now, hope this will help others

In my case the error is caused because I did not set the "Build Action" Property = "Embedded Resource", I took from: tutorial

I got the same error, and i set the BUILD ACTION property of my "Test.sql" file to "Embedded Resource"

Any ideas?

Can you set following and try again?
Copy to output directory: Copy always

28 Ara 2016 20:22 tarihinde "javaman63" notifications@github.com yazdı:

I got the same error, and i set the BUILD ACTION property of my "Test.sql"
file to "Embedded Resource"

Any ideas?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/schambers/fluentmigrator/issues/730#issuecomment-269517875,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJWEWq4AbSXxuE8-yCI3bFn38n6K0Yx_ks5rMqjtgaJpZM4JNTXb
.

I've tried that, but didn't work either

hello,
resource files in project directories are converted to Namespace.DirectoryName.file name so in order to execute files in Scripts directory like this you can use following

namespace XYZ.Migration
{
[Migration(20170418103800878)]
public class FileExecutor20170418103800878 : Migration
{
public override void Up()
{
var url0 = @"XYZ.Migration.Scripts.20170418103800878_1_up.sql";
Execute.EmbeddedScript(url0);
}
...

  1. Change the build action to "Embedded Resource"
  2. If it still cannot find the resource, then please post the output of the following code (to be run from your program):
var asm = typeof(TypeInAssemblyWithEmbeddedMigration).Assembly;
foreach (var n in asm.GetManifestResourceNames())
  Debug.WriteLine(n);

The text is written to the debug output panel of VS.

OK, I figured this out.

The format of the Embedded Script Name is:

ProjectName.FolderNameIfAny.FileNameWithExtension

So, if my project is called MyDatabase, and my script is in a folder called Views and my script is called dbo.GoodStuff.sql then I would make the call like this:

Execute.EmbeddedScript("MyDatabase.Views.dbo.GoodStuff.sql");

You also have to set the file to have its "Build Action" property set to "Embedded Resource".

@fubar-coder I also had this issue after migrating from the non .NET Core version of FluentMigrator to the .NET Core version. To fix the issue, I had to add the .Configure<AssemblySourceOptions> line in the CreateServices function (that was inspired by this tutorial):

            return new ServiceCollection()
                .AddFluentMigratorCore()
                .Configure<AssemblySourceOptions>(x => x.AssemblyNames = new[] { typeof(_001_InitialSchema).Assembly.GetName().Name })
                .ConfigureRunner(rb => rb
                    .AddMySql5()
                    .WithGlobalConnectionString(connectionConfiguration.ConnectionString)
                    .ScanIn(typeof(_001_InitialSchema).Assembly).For.Migrations())
                .AddLogging(lb => lb.AddFluentMigratorConsole())
                .Configure<FluentMigratorLoggerOptions>(options =>
                {
                    options.ShowSql = true;
                    options.ShowElapsedTime = true;
                })
                .BuildServiceProvider(false);

Is this the way to go? If yes, you should update the "quick start" page to document this.

@mabead Just add .For.EmbeddedResources() to the ScanIn.

I followed the advice of @Vaccano and @fubar-coder and it worked.

Was this page helpful?
0 / 5 - 0 ratings