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

PRI: Improve error message when referencing WinUI3 from net5.0 project #361

Open
dotMorten opened this issue Dec 28, 2020 · 13 comments
Open
Assignees
Labels
area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration area-MRTCore ResourceManager feature proposal

Comments

@dotMorten
Copy link
Contributor

Describe the bug
The build error you receive when incorrectly targeting net5.0 instead of net5.0-windows10.0.xxxxx is very unhelpful:

Error	MSB4086	A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "" instead of a number, in condition "'$(TargetPlatformVersion)' >= '10.0.11000.0'".	
ClassLibrary4	C:\Users\mn\.nuget\packages\microsoft.winui\3.0.0-preview3.201113.0\buildTransitive\Microsoft.ApplicationModel.Resources.PriGen.targets	350	

VS also shows the following tooltip error:
image

This issue was reported by a user in the WinUI Discord channel, and didn't know what to do at first. A better error message would have saved the person a lot of time.

Steps to reproduce the bug

  1. Create a new .NET Core class library
  2. Change Target Framework to net5.0
  3. Add WinUI3 package
  4. Compile

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.WinUI" Version="3.0.0-preview3.201113.0" />
  </ItemGroup>
</Project>

Expected behavior
A helpful error that informs the user that they need to retarget.

As an example, see the PR I did for RX.NET here to help users target the correct thing: dotnet/reactive#1442
(just put the .targets file in the net5.0 folder instead of net5.0-windows`

Version Info

NuGet package version:
[Microsoft.WinUI 3.0.0-preview3.201113.0]

Windows app type:

UWP Win32
No No
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop
Xbox
Surface Hub
IoT

Additional context

The main problem is probably that the .targets files aren't in the proper \build\net5.0-windows10.[minversion] folder, so it gets included in every target framework. Once that has moved to a subfolder, the error should go away (as the targets aren't included), and the approach used in the PR referenced above can be used to improve the error message.

@stevenbrix stevenbrix transferred this issue from microsoft/microsoft-ui-xaml Jan 8, 2021
@ghost ghost added the needs-triage label Jan 8, 2021
@stevenbrix
Copy link

I transferred this issue from the WinUI repo since this is an issue with the PRI gen targets. I agree that a better error message telling the user what they need to do would be better.

@stevewri stevewri self-assigned this Jan 11, 2021
@stevewri stevewri added area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration feature proposal and removed needs-triage labels Jan 11, 2021
@andrewleader andrewleader changed the title Improve error message when referencing WinUI3 from net5.0 project PRI: Improve error message when referencing WinUI3 from net5.0 project Feb 3, 2021
@huichen123 huichen123 added the area-MRTCore ResourceManager label Mar 22, 2021
@riverar
Copy link
Contributor

riverar commented Mar 23, 2021

Wanted to add I also hit this with a WPF desktop application project (net5) with the PR metapackage.

@janseris
Copy link

janseris commented Apr 9, 2022

@stevewri Any news? I encountered this error today in a MAUI Preview 14 app and I don't know what to do.

@dotMorten
Copy link
Contributor Author

@janseris this really shouldn’t be an issue with Maui. Are you not multitargeting your Maui app?

@janseris
Copy link

janseris commented Apr 9, 2022

@janseris this really shouldn’t be an issue with Maui. Are you not multitargeting your Maui app?

I am taking this project: https://github.com/jasho/cookbook-maui
And trying to run on Windows Machine.
No modifications to the project or source code are done.
And this appears:
image

When I add net6.0-windows to the .csproj file,a new error - the one from this issue appears.
I am adding it hoping I solve the previous error because I read that the list there is the list of platforms for which the MAUI project will be compiled and I thought Windows was missing. That might not be the case because the default MAUI template does not include net6.0-windows in that list.

image

The project 'CookBook.Mobile' ran into a problem during the last operation: A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "" instead of a number, in condition "'$(TargetPlatformIdentifier)' == 'Windows' and
                                              '$(TargetPlatformVersion)' >= '8.0'".  C:\Users\janse\.nuget\packages\microsoft.windowsappsdk\1.0.0\build\Microsoft.UI.Xaml.Markup.Compiler.interop.targets You may need to reload the solution after fixing the problem. 

I have no idea what causes the issue because I checked the default MAUI Preview 14 (latest) project template .csproj contents and they seem to match the linked project .csproj MAUI project file.

@dotMorten
Copy link
Contributor Author

@janseris ? That’s a different error than what I reported here

@janseris
Copy link

janseris commented Apr 9, 2022

@janseris ? That’s a different error than what I reported here

A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "" instead of a number, in condition "'$(TargetPlatformIdentifier)' == 'Windows' and '$(TargetPlatformVersion)' >= '8.0'".

A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "" instead of a number , in condition "'$(TargetPlatformVersion)' >= '10.0.11000.0'".

I thought these two shared the Platform version number parsing issue.

@tubaplayerdis
Copy link

For me fixing this issue was in the line with net6.0-windows.
For me the application was looking for a target verion and i had to put that in my like this:
net6.0-windows10.0.19041.0

@hdufortlaumie
Copy link

I've a similar issue with WinUI and dotnet 7.
I've create a new WinUI3 project , flipping starget Framework to .Net 7 instead of .Net 6. raise this error:

2022-11-16 15:49:20 Critical Project 'App1' load failed| [MSB4086] A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "" instead of a number, in condition "'$(TargetPlatformVersion)' < '10.0.18362.0'". C:\Users\hugod.nuget\packages\microsoft.windowsappsdk\1.2.221109.1\buildTransitive\Microsoft.InteractiveExperiences.Common.targets at (15:27)

I'm using Visual Studio Pro v17.4.1

@mzanm
Copy link

mzanm commented Nov 18, 2022

Same, switching target framework to dotnet 7 does not work even though it's supposed to be supported.

@francodelucchi
Copy link

francodelucchi commented Dec 10, 2022

For me fixing this issue was in the line with net6.0-windows. For me the application was looking for a target version and i had to put that in my like this: net6.0-windows10.0.19041.0

You saved me with this post, thanks! :-) Exactly the same problem, fixed this way!

@JohnGomes
Copy link

For me fixing this issue was in the line with net6.0-windows. For me the application was looking for a target verion and i had to put that in my like this: net6.0-windows10.0.19041.0

Yup, I had to follow a similar formula -- net{VersionNumber}.0-windows{TargetPlatformMinVersion}
net7.0-windows10.0.17763.0
image

@AnthonyAlexandre
Copy link

JohnGomes... you saved the day... It worked on my Windows App SDK. Now is asking to upgrade some dependency class libraries... i wil do anyways... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration area-MRTCore ResourceManager feature proposal
Projects
None yet
Development

No branches or pull requests