Conversion of Wpf project from .Net framework to .Net5

BigH61 581 Reputation points
2022-03-14T14:02:45.267+00:00

I am trying to migrate a project I found on GetHub NTwainScanProject

from .Net Framework 4.5 to .Net5.

The original code relied on the following third party applications as well as others
GalaSoft.MvvmLight
GalaSoft.MvvmLight.Extras
GalaSoft.MvvmLight.Platform
PropertyChanged

I have removed the above reference as they are incompatible with .Net5 and added the following
Microsoft.Extensions.DependencyInjection
Microsoft.Toolkit.Mvvm
I have made a number of changes but unsure if they are correct as I am unable to resolve the following conversion from GalaSoft.MvvmLight.Ioc

public ViewModelLocator()
{
         ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
         SimpleIoc.Default.Register<MainViewModel>();
}

Any assistance in converting the above or the whole project would be much appreciated.

Developer technologies | Windows Presentation Foundation
{count} votes

Answer accepted by question author
  1. Michael Taylor 61,106 Reputation points
    2022-03-14T14:43:02.503+00:00

    GalaSoft recommends you switch to CommunityToolkit.Mvvm. Therefore I'd recommend you first migrate your app over to this. Since it supports .NET Standard 2.0 you can do this in your existing project.

    Once you've switched to the newer library then switch to .NET 5 from there using the guidelines given here. Actually you'll want to target .NET 6 as .NET 5 is not supported as of late spring of this year.

    Note that Winforms/WPF are a little different than just migrating a console app over. I would probably recommend that you create a brand new WPF project targeting .NET 6. This will contain the necessary project settings to work properly with WPF under .NET 6. Then either copy the relevant sections to your existing project or move your code over to the new project. In my experience this reduces the likelihood of something not working properly. For example Winforms has a special build property that enables the designer. Without it the designer doesn't work properly. Posting a question in the forums related to this would be hard to diagnose unless someone knew you migrated your existing project and therefore were missing a property that is automatically set on new projects.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.