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

New to Add-Migration, can't get it to work #28022

Closed
sjb-sjb opened this issue May 13, 2022 · 5 comments
Closed

New to Add-Migration, can't get it to work #28022

sjb-sjb opened this issue May 13, 2022 · 5 comments

Comments

@sjb-sjb
Copy link

sjb-sjb commented May 13, 2022

I am new to migrations and can't seem to get it to produce the file. I am targeting .NET 6, I created my app with the "Blank App, Packaged (WinUI 3 in Desktop)" template and two libraries with the "Class Library (WinUI 3 in Desktop)" template. The context is in one of the libraries ("Q5U"). Below shows what happens when I try Add-Migrate. There is a pause before it returns the last prompt so it looks like it's doing something but I don't see the output file anywhere. I also tried the -Output option to no avail.

I feel like I'm missing something basic ... ?

To allow migrations to create the context I created a factory and specified UseSqlite. Since there is no pre-existing database file I left the file name out of the UseSqlite call.

Context factory

    public class AcContextDesignTimeFactory: IDesignTimeDbContextFactory<AcContext>
    {
        public AcContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder<AcContext>();
            optionsBuilder.UseSqlite<AcContext>();
            DbContextOptions<AcContext> options = optionsBuilder.Options;
            return new AcContext(options);
        }
    }

Results

PM> Add-Migration InitialCreate -Project Q5U -Context AcContext -Namespace Q5.Container -Verbose
Using project 'Q5U'.
Using startup project 'App'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.deps.json" --additionalprobingpath C:\Users\steve.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --runtimeconfig "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.runtimeconfig.json" C:\Users\steve.nuget\packages\microsoft.entityframeworkcore.tools\6.0.3\tools\netcoreapp2.0\any\ef.dll migrations add InitialCreate --json --namespace Q5.Container --context AcContext --verbose --no-color --prefix-output --assembly "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\Q5U.dll" --project "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\Q5U\Q5U.csproj" --startup-assembly "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.dll" --startup-project "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\App.csproj" --project-dir "C:\Users\steve\OneDrive\Documents\VS Projects\Q5\Q5U\" --language C# --configuration Debug --working-dir "C:\Users\steve\OneDrive\Documents\VS Projects\Q5" --root-namespace Q5U --nullable
Using assembly 'Q5U'.
Using startup assembly 'App'.
Using application base 'C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App\bin\x64\Debug\net6.0-windows10.0.19041.0\win10-x64'.
Using working directory 'C:\Users\steve\OneDrive\Documents\VS Projects\Q5\App'.
Using root namespace 'Q5U'.
Using project directory 'C:\Users\steve\OneDrive\Documents\VS Projects\Q5\Q5U'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'App'...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'AcContext'.
Using DbContext factory 'AcContextDesignTimeFactory'.
PM>

@AndriySvyryd
Copy link
Member

@bricelam

@bricelam
Copy link
Contributor

@sjb-sjb

Can you share a simplified repro project so I can investigate further? Something seems to be silently terminating the tool...

@sjb-sjb
Copy link
Author

sjb-sjb commented May 17, 2022

Easier said than done, it is a large project. But what I take from your comment is that there is nothing obvious from the Verbose messages, in other words this is not just my imagination. I will try to develop a small repro.

@AndriySvyryd
Copy link
Member

EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?

Steps to reproduce

Ideally include a complete code listing that we can run to reproduce the issue.

Alternatively, you can provide a project/solution that we can run.

BTW we're not just doing this to be mean 😄... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we ask that folks give us a self-contained way to reproduce an issue.

For a guide on submitting good bug reports, read Painless Bug Tracking.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@sjb-sjb
Copy link
Author

sjb-sjb commented Jun 3, 2022

Sorry I didn't have time to get to this right away. It does look like a bug.
@AndriySvyryd please see #28149 .

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

4 participants