johnildergleidisson
johnildergleidisson

Reputation: 2117

Deploying a WPF application that uses Entity Framework Core

I want to build a WPF app that uses entity framework core so that I can handle SQLite databases.

I then do the following, for instance:

<Window x:Class="WPFEFCoreDeploymentTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Click="ButtonBase_OnClick"></Button>
    </Grid>
</Window>
namespace WPFEFCoreDeploymentTest
{
    using System.Linq;
    using System.Windows;
    using Microsoft.EntityFrameworkCore;

    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            using (var context = new SomeContext())
            {
                if (context.Database.GetPendingMigrations().Any())
                {
                    context.Database.Migrate();
                }
            }
        }
    }

    public class SomeContext : DbContext
    {
        public DbSet<Test> Tests { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Data Source=local.db");
        }
    }

    public class Test
    {
        public int Id { get; set; }
    }
}

Now, if I go to the bin/Debug folder for my project, I notice that there are many DLLs that I assume to be the .NET core's implementation of the .NET standard (maybe I'm just being very stupid), for instance:

So, if I understand correctly, when no redirects are added to the config app.config, these signed assemblies have to be accessible to the executable, meaning if I create an installer, I have to deploy these assemblies along with my application. But .NET framework already implement these, and .NET framework must be installed if someone wants to execute the WPF application on their machines. This makes me wonder:

  1. Can I replace these .net core implementation assemblies with .net framework's implementation? Is it possible?
  2. If the former point is technically possible, should it work or this may create all sorts of problems?
  3. If not possible, is it expected that mixing both .net framework and .net core will potentially lead to having duplicate implementations of assemblies referenced directly or indirectly by your application (maybe other modules of my application uses .net framework's System.Net.Http.dll classes but EF core or its dependencies references .net core's System.Net.Http.dll as well)?

Upvotes: 10

Views: 4779

Answers (1)

user7488587
user7488587

Reputation:

Short answer to:

Can I replace these .net core implementation assemblies with .net framework's implementation? Is it possible?

No. If your application is written in .NET Core you can't. Also you shouldn't. I would rather go with the .NET Core assemblies, when possible.

Edit: Because you are using .NET Framework for your WPF appliation already you could uninstall the .NET Core implementations and just install the .NET Framework. But if you play to go with your app on another platform than windows you should be going with .NET Core assemblies.

Upvotes: 1

Related Questions