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

Binding projects don't work properly when used as project references #10148

Open
rolfbjarne opened this issue Nov 24, 2020 · 11 comments · May be fixed by #18766
Open

Binding projects don't work properly when used as project references #10148

rolfbjarne opened this issue Nov 24, 2020 · 11 comments · May be fixed by #18766
Assignees
Labels
binding-projects Issue or PR that affects binding projects bug If an issue is a bug or a pull request a bug fix iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Projects
Milestone

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented Nov 24, 2020

Repro:

  • Open tests/tests.sln in VSMac.
  • Build the framework-test project.
  • Open the FrameworkTests.cs file.

Any API used from the bindings-framework-test project are squiggly red, and intellisense doesn't work:

Screen Shot 2020-11-24 at 21 36 47

This is something we have to fix in our msbuild logic somewhere.

Note that building the solution actually works, this just affects editing experience in the IDE (intellisense doesn't work).

A potential workaround is to build the binding project separately, and then just reference the binding assembly (.dll) in the main project instead.

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac iOS Issues affecting Xamarin.iOS labels Nov 24, 2020
@rolfbjarne rolfbjarne added this to the Future milestone Nov 24, 2020
@rolfbjarne rolfbjarne modified the milestones: Future, .NET 8 Oct 6, 2022
@rolfbjarne rolfbjarne added this to Bugs in .NET 8 - Themes Oct 6, 2022
@rolfbjarne
Copy link
Member Author

I believe the problem is that our MSBuild logic doesn't have support for design-time builds: https://github.com/dotnet/project-system/blob/main/docs/design-time-builds.md#what-is-a-design-time-build

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Nov 22, 2022
@rolfbjarne
Copy link
Member Author

Some very early and incomplete work: rolfbjarne@216aeca

@Hooterr
Copy link

Hooterr commented May 16, 2023

I'm seeing exactly the same with net7.0 and a macOS binding library.
VS studio can't find the namespace or any types in it, but the project builds and works with no problems. It's quite annoying though, since you can't use Intellisense and you have to constantly refer to the ApiDefinition file.

@rolfbjarne rolfbjarne self-assigned this Jun 23, 2023
@brunck
Copy link

brunck commented Jul 11, 2023

I worked around this by referencing the binding project assembly directly, which I build in a separate solution. This allows Intellisense to work but does require a bit of gynmastics in my automated build process.

@rolfbjarne
Copy link
Member Author

This is best done as part of making binding projects compile directly on Windows (#16611), because we don't want to do design-time builds remotely.

@rolfbjarne rolfbjarne modified the milestones: .NET 8, .NET 9 Sep 12, 2023
@rolfbjarne rolfbjarne removed this from Bugs in .NET 8 - Themes Sep 12, 2023
@rolfbjarne rolfbjarne added this to Features in .NET 9 Sep 12, 2023
@microspaze
Copy link

microspaze commented Oct 9, 2023

My workaround is:

  1. Modify binding project's output folder to bin root by setting '<OutputPath>bin</OutputPath>' and '<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>'
<PropertyGroup>
    <TargetFramework>net7.0-ios</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>true</ImplicitUsings>
    <IsBindingProject>true</IsBindingProject>
    <Configurations>Debug;Release</Configurations>
    <Platforms>AnyCPU</Platforms>
    <OutputPath>bin</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>
  1. Add binding project's dll to consumer project as a Assembly refererence.
<ItemGroup>
    <Reference Include="xxxx">
      <HintPath>..\xxxx\bin\xxxx.dll</HintPath>
    </Reference>
  </ItemGroup>

@cho-trackman
Copy link

@microspaze it's not always enough for the IntelliSense to work properly at all times. On top of that the referenced framework/lib is often not updated without a hard clean (delete obj/bin) leading to unrecognized selectors.

My solution for now is to copy the intermediate generated files under obj (*.g.cs) to the main project. Also the <NativeReference ...> is in the main project. No project or dll ref. Only thing is <AllowUnsafeBlocks>true</AllowUnsafeBlocks> in the main project does not look "nice".
Anybody else found a better solution?

@microspaze
Copy link

@cho-trackman
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> is not necessary if there is 'unsafe' keyword property in your binding project. And everytime you modify the binding project, you need to build the binding project. Then you can have the IntelliSense for the consumer project.

But I had nerver faced with the unrecognized selectors for referenced framework/lib issue. It works fine for me on my currently working-on project: IJKPlayer.Binding

@jurganson
Copy link

So this is still an issue in .NET MAUI (as I presume it's perhaps part of VS studio's IntelliSense?) and I was wondering if there is any movement on this. Otherwise, could it be moved to the .NET MAUI repository as an issue? Using the .dll as a reference is working for now, but I know some developers would like to keep their solutions together, for easier maintenance and transparency.

@rolfbjarne
Copy link
Member Author

So this is still an issue in .NET MAUI

Yes, it's still an issue.

I was wondering if there is any movement on this.

I've started working on this, but it will take a while, because it's not very high priority and I ran into some complications. I'm hoping to get it done for .NET 9, but no promises.

Otherwise, could it be moved to the .NET MAUI repository as an issue?

No, because it's not an issue in MAUI specifically, but in this repository.

@jurganson
Copy link

Glad to hear its in the pipeline, thanks for the quick reply @rolfbjarne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-projects Issue or PR that affects binding projects bug If an issue is a bug or a pull request a bug fix iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Projects
.NET 9
Features
6 participants