opentk / GLControl

WinForms control for OpenTK 4.x.
https://opentk.net
Other
54 stars 24 forks source link

Xamarin.Forms.Platform.WPF dependency issue using .Net5.0 #8

Closed topeterk closed 2 years ago

topeterk commented 3 years ago

Hi, maybe you guys know, how to handle this problem:

I'm trying to build a WPF application using Xamarin by targeting .Net5.0. But I cannot figure out any way of getting this working as it looks like that <PackageReference Include="Xamarin.Forms.Platform.WPF" Version="5.0.0.2012" /> will implictily load OpenTK.GLControl in version 3.0.1 as this is the latest one. But it is not compatible with the <TargetFramework>net5.0-windows</TargetFramework>. OpenTK 4.4.0 seem to be compatible but it is not providing OpenTK.GLControl via NuGet, so this doesn't help me either.

Any idea what I am missing?

My hope was building this project here and just replace the dependency from the NuGet packages of OpenTK.GLControl. But I cannot get rid of this dependency error: image

Can this approach even work (replacing the dependency)?

Any help is appreciated!

Thanks, Peter

seanofw commented 3 years ago

I don’t know for sure if that’ll work, but you can try it with an updated Nuget package. There is a Nuget package for the new GLControl, but @varon has been too busy to switch it over to the official account. You could try downloading it to your local Nuget folder and see if it gets picked up properly.

https://www.nuget.org/packages/OpenTK.WinForms/4.0.0-pre.5

topeterk commented 3 years ago

With enabling the preview versions I found and integrated this version into the project.

The visual studio project keeps showing me as target framework ".NET 5.0" now, which is good (previously as it was "empty" after adding the Xamarin.Forms.Platform.WPF NuGet package. However, the NuGet package for OpenTK.GLControl in version 3.0.1 was still added to the project and still shows me an incompatibility warning.

Just for my understanding, the OpenTK.WinForms is the "successor" of OpenTK.GLControl and (in the future) should be used as replacement of the OpenTK.GLControl dependency in Xamarin.Forms.Platform.WPF? Or will it be released as OpenTK.GLControl 4.x.x?

seanofw commented 3 years ago

I can't really speak about Xamarin, since I really don't know it.

OpenTK 4.0 was a major rewrite/restructuring of OpenTK; it has some similarities to OpenTK 3, but under they hood, they're very, very different. Likewise, the OpenTK GLControl 4 is a near-total rewrite; and while it has a similar API to the OpenTK GLControl 3, it's almost completely different code under the hood, designed for the needs of OpenTK 4 and .NET Core.

So OpenTK 4 is a successor to OpenTK 3; it's for .NET Core and .NET 5+, while OpenTK 3 is for .NET Framework 4.x and earlier. The GLControl 4 is not really a direct successor to GLControl 3; it's more of an equivalent control, but for OpenTK 4, if that makes sense. It replaces the GLControl 3 in a lot of instances, but it's only superficially similar to the old control, so I don't know if it's an exact replacement for your needs.

However, it will be released as the new OpenTK.GLControl Nuget package at some point when @varon can get to it.

topeterk commented 3 years ago

Hmm okay, I understand.

A (preview) release of OpenTK.GLControl would be great because this will eventually eliminate the NuGet dependency issues. I know it can be quite hard to keep the "old API" alive while reworking the back end.

Until new NuGet packages become available, I will try figuring out if I can get it running with the locally built version. Or I have to fallback to .Net Framework in the meantime.

Thank you!

seanofw commented 3 years ago

The preview release is the link I provided above. Eventually, @varon will just move it from the account @bezo97 created it in to be owned by OpenTK instead, and then it'll be the official new release.

Hope that helps!

topeterk commented 3 years ago

For me, it looks like that NuGet sees "OpenTK.WinForms" != "OpenTK.GLControl" and that is why it loads OpenTK.GLControl even when OpenTK.WinForms is already part of the project's available NuGet packages. Can those names actually be different or it this the reason for "bypassing" the NuGet dependencies - I'm not so familiar with the NuGet "behind the scenes".

seanofw commented 3 years ago

NuGet goes by the package names, not the namespaces; but it wouldn't surprise me if they're different enough that it just assumes they're different packages. You may need a special version of the new GLControl package to satisfy the dependency, and even so, that's no guarantee that the new GLControl is compatible enough that Xamarin's WPF code will accept it.

Looking at what you're doing, I realized you're doing WPF, so it's worth pointing out that there's a native OpenTK WPF control in development as well. You may want to consider looking at that project for your needs: It's not a wrapper around WinForms, but is a real, native WPF control. I don't know whether Xamarin will like that either, but I suspect that may lead to better results than trying to hack the new GLControl into Xamarin's dependency chain. I don't follow that project closely, but you could try seeing if their control meets your needs better.

topeterk commented 3 years ago

Interesting .. I was following this guide here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/wpf Unfortunately it seems to me, the guide is out of date as it uses .Net Framework in its example but I haven't found any example for .Net 5.0 anywhere on the internet. It feels like I'm the first and only one actually doing this.

WindowsForms was not really listed for a Xamarin application and I'm not sure if UWP would fit my needs, so I though about using WPF - maybe I have to rethink that. I'm still surprised that I ran into OpenTK at all as I expected the full WPF stack being provided by Microsoft.

By now, cross platform development worked a lot better for me with .Net Framework 2.0: One file that can be launched on Windows, Linux and Mac even with a GUI. By running into this Xarmarin complexity, its dependencies and incompatibilities, I'm not sure if I should continue at all porting my old application to the "latest and greatest" technology 🤔

seanofw commented 2 years ago

Since this issue hasn't had any activity in several months, I'm going to close it. If you have other questions, please open another issue.

NogginBops commented 2 years ago

I'll add here that if you are using Wpf you might want to look into the OpenTK.GLWpfControl package as it provides a control better suited for Wpf

topeterk commented 2 years ago

I just want to use Xamarin on various platforms. As it is not portable I have to choose platform specific parts for like iOS, Android or Desktop like using GTK or WPF. For WPF the way to go is using Xamarin.Forms.Platform.WPF but this package (not myself!) is referring to old OpenTK version, so it blocks upgrading to .Net5 as OpenTK version 3 does not support .Net5. Do you mean by that, that I can somehow replace OpenTK 3 references from Xamarin.Forms.Platform.WPF with (a specific? version of) OpenTK.GLWpfControl instead?

NogginBops commented 2 years ago

Atm it's currently impossible to run newer versions of OpenTK on Xamarin due to this issue. Xamarin has not considered changing this until recently when they finally (after 8 years) decided to make a binary breaking change. This issue can be tracked at https://github.com/xamarin/xamarin-macios/issues/13160 and should be fixed in the upcomming release of .net 6 (November 9th).