I am using a class library for tests and I need to configure DryIoc, so I reference the Nuget package Prism.DryIoc. Note that I am working on a Xamarin solution and do not have (or need) any WPF (or other Windows) components.
When my class library is set to .NET Core 3.1, it compiles correctly. If I change it to .NET 5.0 or .NET 6.0 however, I get this error:
Error NETSDK1136 The target platform must be set to Windows (usually by including '-windows' in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so. C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets 250
When I review the references from Prism.DryIoc I see that it references Prism.Wpf.
Does anyone know a way to complete remove any Wpf dependencies, so that I can compile my library directly with .NET 6.0 without issues and without having to specify Windows as target framework?
Steps to reproduce:
Sample class library attached.
For anyone coming here in the future: The correct package to use with any Xamarin application is Prism.DryIoc.Forms (and not Prism.DryIoc) as described here.
My project was using Prism.DryIoc in order to create a DryIoc bootstrapper inheriting from PrismBootstrapperBase, which is in the Wpf project. I solved the problem by extracting the needed code from PrismBootstrapperBase and removing the reference to Prism.DryIoc. Here is the bootstrapper's code for reference:
public class TestsBootstrapper
{
#region Properties
IContainerExtension _containerExtension;
public IContainerProvider Container => _containerExtension;
#endregion
#region Run
public void Run()
{
ContainerLocator.SetContainerExtension(CreateContainerExtension);
this._containerExtension = ContainerLocator.Current;
RegisterTypes(this._containerExtension);
this._containerExtension.FinalizeExtension();
}
private IContainerExtension CreateContainerExtension()
{
return new DryIocContainerExtension(new Container(DryIocContainerExtension.DefaultRules));
}
#endregion
#region RegisterTypes
private void RegisterTypes(IContainerRegistry container)
{
// Add required registratoins here
}
#endregion
}
Xamarin Forms uses .Net Standard 2.0 or 2.1 libraries. It is not compatible with .Net Core or .Net 5-6 projects, nor will it be until it is Migrated to Maui in 2022. At which point it will use .Net 5 as standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With