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

Framework is not recognized on WPF even with HAS_WPF #33

Open
MitchRazga opened this issue Jan 11, 2024 · 5 comments
Open

Framework is not recognized on WPF even with HAS_WPF #33

MitchRazga opened this issue Jan 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@MitchRazga
Copy link

Describe the bug

Hi,
I've trying to get this generator to work with an existing WPF project.
DependencyPropertyGenerator does not seem to work when the project has other packages with custom targets. For example CompiledBindings

I thought that is was just not passing the DefineConstants but that doesn't seem to be the case:
Image1

The generated editorconfig also seems to have the correct data:

build_property.RecognizeFramework_DefineConstants = TRACE,HAS_WPF,DEBUG,NET,NET8_0,NETCOREAPP
build_property.UseWPF = true

Steps to reproduce the bug

Please see attached repro.
DependencyPropertyGeneratorTest.zip

I've also included another project with a launch profile to help with debugging the source generator. To use:

  1. Set startup project to DebugRoslyn
  2. Uncomment line in App.xaml.cs and Go To Definition for H.Generators.Extensions.AnalyzerConfigOptionsProviderExtensions.TryRecognizeFramework.
  3. Add first breakpoint on line 142 and then re-comment the line in App.xaml.cs
  4. Run DebugRoslyn
  5. Add second breakpoint on line 147, you may need to click "Disable managed optimizations and restart debugging".
    Image2

Interestingly it looks like it detects the framework when run from the debugger just not when building the actual project.

Expected behavior

No response

Screenshots

No response

NuGet package version

1.4.0

IDE

Visual Studio 2022

Additional context

I've tried adding a .props file as recommended in https://github.com/HavenDV/H.Generators.Extensions but no luck there.

With the roslyn debugger on a PackageReference the CompilerAnalyzerConfigOptions.GlobalOptions looks like
image

I cloned the main branch to see if there was difference when using ProjectReference instead and when using the debugger the CompilerAnalyzerConfigOptions.GlobalOptions looks like
image

@MitchRazga MitchRazga added the bug Something isn't working label Jan 11, 2024
@HavenDV
Copy link
Owner

HavenDV commented Jan 11, 2024

Hi.

At first glance, it seems to me that the problem may be due to the fact that one of the packages in the project defines in its NuGet .props file, using the syntax <DefineConstants>NEW_CONSTANT</DefineConstants> instead <DefineConstants>$(DefineConstants) ;NEW_CONSTANT</DefineConstants>
I will look deeper

@taenito
Copy link

taenito commented Sep 11, 2024

Hi.
Any news on this? I have the same error with MAUI when I create a UnitTests project and a MAUI class library project.
I can't force le Framework with HAS_MAUI.

@HavenDV
Copy link
Owner

HavenDV commented Sep 11, 2024

Strangely, I use this extensively in MAUI projects without the need for HAS_MAUI

@HavenDV
Copy link
Owner

HavenDV commented Sep 11, 2024

Maybe there is something that prevents detection? Like UseWinUI. But UseMaui has priority.

Here is the current detection code of the current framework: https://github.com/HavenDV/H.Generators.Extensions/blob/main/src/libs/H.Generators.Extensions/AnalyzerConfigOptionsProviderExtensions.cs#L141

@taenito
Copy link

taenito commented Sep 12, 2024

Do you have a unit tests in your maui project?

I tried the two configurations presented by Microsoft (https://learn.microsoft.com/en-us/dotnet/maui/deployment/unit-testing?view=net-maui-8.0).

MAUI app project :
App -> net8.0;net8.0-android;net8.0-ios
App.UnitTests -> net8.0

I get the "Framework is not recognized" error and net8.0 compatibility error from 2 libs (not your lib).

MAUI class library project :
App.Core -> MAUI class library project -> net8.0;net8.0-android;net8.0-ios
App -> MAUI app project -> net8.0-android;net8.0-ios (reference App.Core)
App.UnitTests -> net8.0 (reference App.Core)

I get the "Framework is not recognized" error when I add package reference to DependencyPropertyGenerator into the App.Core project.

I have this on all projects

<UseMaui>true</UseMaui>
<DefineConstants>$(DefineConstants);HAS_MAUI</DefineConstants>

And I tried with this too

<RecognizeFramework_DefineConstants>$(RecognizeFramework_DefineConstants);HAS_MAUI</RecognizeFramework_DefineConstants>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants