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

Proposal: GenericHost support for Add-Migration #8619

Open
Reza-Noei opened this issue Jul 8, 2023 · 2 comments
Open

Proposal: GenericHost support for Add-Migration #8619

Reza-Noei opened this issue Jul 8, 2023 · 2 comments
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team

Comments

@Reza-Noei
Copy link

Reza-Noei commented Jul 8, 2023

Previously I have used different patterns to make Add-Migration works. Design-Time factory works fine for me in WinUI3.

but later on we added GenericHost to our WinUI3 app.

I've tried to remove these Design-Time factories and follow Application Service pattern. because it works with my configurations while Design-Time factory doesn't. So I don't needed to hard-code my ConnectionStrings in the code base.

But I'm getting this error when I'm running Add-Migration:

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing
without the application service provider. Error: Unable to load DLL 'Microsoft.ui.xaml.dll'
or one of its dependencies: The specified module could not be found. (0x8007007E)
Unable to create an object of type 'BusinessDomainContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

here is my command:

Add-Migration InitialCreate2 -Context BusinessDomainContext -OutputDir Migrations\BusinessDomain

I don't understand the source of this problem.

At the next step I've tried to add below config to my *.csproj. Error got solved:

<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

But Nothing happened after that.
Using --verbose I've got this logs:

 Using project directory 'D:\...' Remaining arguments: .
 Finding DbContext classes...
 Finding IDesignTimeDbContextFactory implementations...
 Finding application service provider in assembly 'DesktopApplication'...
 Finding Microsoft.Extensions.Hosting service provider...
 Using environment 'Development'.

At the next step I have tried to DISABLE_XAML_GENERATED_MAIN by updating *.csproj file.

	<DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>

I have added new Program.cs file. with this content:

public static void Main(string[] args) 
    => CreateHostBuilder(args).Build().Run();

// EF Core uses this method at design time to access the DbContext
public static IHostBuilder CreateHostBuilder(string[] args)
=> Host.CreateDefaultBuilder(args).ConfigureServices(services=>
{
    services.AddDbContext<BusinessDomainContext>(options =>
    {
        options.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=aa.BusinessDomain;Integrated Security=True;MultipleActiveResultSets=true;");
    });
});

For me, I looks terrific, But it works.
There is an open Issue for this which is open from 2022. and the thing I've done looks bad. I think Microsoft should release WinUI3 in compatible form. I should not re-invent things to getting it to work.

@soroshsabz
Copy link

ITNOA

I think it is Bug and not feature

/bug

@soroshsabz
Copy link

cc @bpulliam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

3 participants