dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

ApplicationVersion <> 1.0 in solution with UnitTestProject causes compile errors #25828

Open cckring opened 1 week ago

cckring commented 1 week ago

Description

We have a feature rich MAUI application for iOS and Android which unfortunately does not have any unit tests.

I have followed the guide setting up the MAUI app and then I have added a UnitTest project also following the guide.

However I have found that my solution will only compile if I put 1.0 in the ApplicationDisplayVersion

    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>

When I put the correct value 2.5.0 for our app in the

    <ApplicationDisplayVersion>2.5.0</ApplicationDisplayVersion>

The solution will not compile.

I have just tried to download Gerald Versluis' sample project. In that I can reproduce the same error when I replace 1.0 with 2.5

I get this build error:

2>Build started 12/11/2024 14.56.51.
2>Target ResolvePackageAssets:
2>  C:\VSDev\MauixUnitTestSample\UnitTestProject\UnitTestProject.csproj : error NU1201: Project MauixUnitTestSample is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project MauixUnitTestSample does not support any target frameworks.
2>Done building target "ResolvePackageAssets" in project "UnitTestProject.csproj" -- FAILED.
2>
2>Done building project "UnitTestProject.csproj" -- FAILED.
2>
2>Build FAILED.
2>
2>C:\VSDev\MauixUnitTestSample\UnitTestProject\UnitTestProject.csproj : error NU1201: Project MauixUnitTestSample is not compatible with net8.0 (.NETCoreApp,Version=v8.0). Project MauixUnitTestSample does not support any target frameworks.
2>    0 Warning(s)
2>    1 Error(s)

WHen I open the file MauixUnitTestSample\MauixUnitTestSample\obj\project.assets.json I see this information which inspired me to try to change the ApplicationDisplayVersion.

  "logs": [
    {
      "code": "NU1105",
      "level": "Error",
      "message": "Unable to read project information for 'MauixUnitTestSample': The property PackageVersion was expected to have a single value across all target frameworks, but instead had the following values: 1.0.0, 2.5.0"
    }

I trust that you can just try the same with Gerald's project?

Steps to Reproduce

  1. Clone Gerald Versluis' sample project: https://github.com/jfversluis/MauixUnitTestSample
  2. Open \MauixUnitTestSample\MauixUnitTestSample.csproj
  3. Change 1.0

    to

    2.5.0

Link to public reproduction project repository

https://github.com/jfversluis/MauixUnitTestSample

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

In our production app I manually change the 2.5.0 to 1.0.0 when I need to run the tests.

I am in the process of putting it into a Visual Studio App configuraiton, but have not done so yet.

Relevant log output

similar-issues-ai[bot] commented 1 week ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

Zhanglirong-Winnie commented 1 week ago

This issue has been verified using Visual Studio 17.13 Preview 1(9.0.0-rc.2.24503.2 & 8.0.82 & 8.0.93). Can repro this issue.

mattleibow commented 3 days ago

I think this is because ApplicationVersion is a MAUI platform feature and it is used to set Version which in turn sets PackageVersion. However, the net8.0 TFM does not have any of this and stays 1.0.

To fix this, make sure to set the PackageVersion to match ApplicationVersion..