Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-Migration on any dotnetcore project #7905

Closed
ojorma opened this issue Mar 16, 2017 · 7 comments
Closed

Add-Migration on any dotnetcore project #7905

ojorma opened this issue Mar 16, 2017 · 7 comments

Comments

@ojorma
Copy link

ojorma commented Mar 16, 2017

I get an error when I to run add-migration with entitcore on any dotnetcore based project but the equivalent command works when targeting the full dotnetframework

Add-Migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
Parameter name: basePath"
At line:1 char:1

  • Add-Migration init
  •   + CategoryInfo          : NotSpecified: (:) [Add-Migration], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentException,Add-Migration
    
    
    

see a snapshot of my code. It's a dotnetcore console app. Thesame will work if created the project based on dotnetframewok 4.6.1

Steps to reproduce

entitycorebug

Further technical details

Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system:
IDE: (e.g. Visual Studio 2017)

@bricelam
Copy link
Contributor

What version of Microsoft.EntityFrameworkCore.Tools are you using? Does -Verbose give additional information?

@ojorma
Copy link
Author

ojorma commented Mar 16, 2017

@bricelam thanks for the response. I figured it out and posted the answer here
#7540 (comment)

@dvdobrovolskiy
Copy link

Seems like #7540 (comment)
does not work in my case

Suddenly got
add-migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null ch
aracter.
after adding one new field to existing model.

@petersgiles
Copy link

I'm getting this as well

add-migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
PM> dotnet --version
2.0.0

not at all sure how to proceed

@petersgiles
Copy link

petersgiles commented Sep 18, 2017

I think I have worked something out.

  • I have my Data Model in a netstandard2.0 class library
  • I have a MVC (whatever the latest core 2.0 one is) app that I am using as the startup app required by EF Core 2.0. I'm mostly just scaffolding my data context in the MVC app.
  • dotnet --version is 2.0
  • I run add-migration Initial from the Package Manager Console
  • When I add a migration I get the "AddFromFile" error

What works though is adding a core 2.0 console app to the solution (not editing the code) and setting that as my startup project just before running the add-migration command.

So it would seem that there's some code in the web app that gets run when the app-mrigations command is issued.

I'm guessing its the Main method...here's mine

    public class Program
    {
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService<AdminDataContext>();
                    DbInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService<ILogger<Program>>();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }

        public static IWebHost BuildWebHost(string[] args)
        {
            return WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
        }
    }

I can only assume there's something path-y going on when constructing the host that isn't working from the package manager console.

I hope this gives someone who knows better a hint as to what is going on with this.

EDIT:

It looks like something I'm doing when building my container in the Startup class's ConfigureServices method

@rsandhumcr
Copy link

rsandhumcr commented Sep 24, 2017

I had the same problem with .net core 1.1 .
I solved my problem by creating a console app in my solution and make it start up project.
Made a reference to the project containing my written db context in the console app.
Executed the 'Add-Migration Initial' with success.

@gharajedaghi
Copy link

Add-Migration Initial with success.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants