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

Xamarin.Mac application targetting .NET Framework 4.7.1 gets incorrect references #215

Closed
fschwiet opened this issue Dec 31, 2018 · 7 comments
Labels

Comments

@fschwiet
Copy link

fschwiet commented Dec 31, 2018

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When adding a reference to Nuget package ReactiveUI (which in turn pulls in Splat) to a Mac application that is targeting .NET framework 4.7.1 we end up with the wrong references in the project file (to things like PresentationFramework). I am creating this bug in the Splat repository because the libraries being pulled in are referenced from https://github.com/reactiveui/splat/blob/master/src/Splat/Splat.csproj#L35.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

An example project is here: https://github.com/fschwiet/MacSplatConsole/tree/xamarin-mac-full-presentationframework-reactiveui-9.6.3. In the below repro steps I will reference a corresponding commit you can look at.

You'll see in the last commit that some libraries like PresentationFramework and PresentationCore are targeted. The project still builds and runs, but if I try to use ReactiveUI it doesn't work.

As an example of things not working, if I add code:

using System;
using System.Reactive.Linq;
using ReactiveUI;
...
    Observable.Timer(TimeSpan.FromSeconds(3)).ObserveOn(RxApp.TaskpoolScheduler).Subscribe(

somewhere I get complaints about needing to add a reference to WindowsBase or System.Windows.Forms.

What is the expected behavior?

When I add the nuget package I should get libraries that are available to Xamarin.Mac applications.

What is the motivation / use case for changing the behavior?

I am going to error on giving you too much information below. The above repro I think isolates my concern though I suspect I am barking up the wrong tree.

We have some existing code using ReactiveUI we're trying to package into a UI-less app to run as an embedded service. We don't want to package this as a regular Xamarin.Mac application since that would spawn a window and add a system tray icon. I think most of our usages of ReactiveUI in the packaged code are related to scheduling (using the schedulers in RxApp).

So I went down the route of trying to create a console application with Xamarin.Mac bindings according to the instructions here: https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/console. In short, the process is to create a .NET Console Project (.NET, not .NET core) and manually bind some things to get cocoa API support / Xamarin.Mac goodness. Such projects have the same targeting issues as the project created in these repro steps (the target framework rule for net461 in splat.csproj is invoked).

I thought I could resolve the targeting issues by referencing DLLs directly, bypassing nuget (inspired by https://stackoverflow.com/questions/49598467/how-to-choose-target-framework-from-nuget-package). So I created a regular .Mac app alongside the console app, added the nuget package to the regular app then ported the changes over to the console app so I could choose the DLLs being used. This didn't quite work, the last error I ran into was that it couldn't find System.Reactive.dll.

Which versions of ReactiveUI, and which platform / OS are affected by this issue? Did this work in previous versions of ReativeUI? Please also test with the latest stable and development snapshot

macOS High Sierra 10.13.6,
xCode version 10.1,
Visual Studio for Mac 7.7.2
Xamarin.Mac tooling v5.2.1.12

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Thanks for all the hard work on ReactiveUI. There is an existing closed issue #48 with similar symptons, but its from 2014 so I'm not sure how related it is.

@clairernovotny
Copy link
Member

If you're targeting .NET 4.7.1, then there's nothing we can do. We have a Xamarin.Mac target, but if it's not choosing that one, the bug is either in NuGet or VSfM.

@fschwiet
Copy link
Author

If you're targeting .NET 4.7.1, then there's nothing we can do

I presume this statement applies to .NET 4.6.1 and 4.7 as well (these won't work either) but if I'm mistaken let me know.

@clairernovotny
Copy link
Member

That's correct. The Xamarin.Mac app needs to use the Xamarin.Mac target in the package as that's the one that has the right references for that platform.

@fschwiet
Copy link
Author

fschwiet commented Dec 31, 2018

I just wanted to explicitly call out the change in target in the repro mac app that is problematic:

In commit fschwiet/MacSplatConsole@54af128 the targeting changes from:

    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
     <TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>

to

     <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
     <UseXamMacFullFramework>true</UseXamMacFullFramework>

I'm not sure nuget can do a better job. I wonder if its looking for the target monomac (https://docs.microsoft.com/en-us/nuget/reference/target-frameworks) and not finding it, if thats the case I wonder if Splat.csproj could reference functioning libraries for that target (it could be this scenario is completely unworkable).

Sorry just thinking aloud on this one as I'll need to come back to investigate.

NuGet target framework references identify and isolate framework-dependent components of a package.

@clairernovotny
Copy link
Member

This has been a long-standing issue that the NuGet team refuses to fix:

NuGet/Home#2662

@fschwiet
Copy link
Author

Oren thank you for sharing your knowledge on these things.

@glennawatson
Copy link
Contributor

I would recommend you upvote that nuget issue if you can.

@lock lock bot added the outdated label Jun 24, 2019
@lock lock bot locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants