6

I have a .net maui app that I migrated from Xamarin Forms. I can build fine on Azure DevOps and on my Mac. But when I try to build it on Windows in Visual Studio I get this error message:


Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-android'. Ensure that restore has run and that you have included 'net6.0-android' in the TargetFrameworks for your project.

Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-windows10.0.22621.0'. Ensure that restore has run and that you have included 'net6.0-windows10.0.22621.0' in the TargetFrameworks for your project.

Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.

Assets file '..obj\project.assets.json' doesn't have a target for 'net6.0-ios'. Ensure that restore has run and that you have included 'net6.0-ios' in the TargetFrameworks for your project.

My csproj looks like this. I tried to compare that to a project generated from the template (which I can build fine), and remove differences but the error did stay the same.

    <PropertyGroup>
        <TargetFrameworks>net6.0-ios;net6.0-android;net6.0</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.22621.0</TargetFrameworks>
        <OutputType>Exe</OutputType>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>   
        <Nullable>enable</Nullable>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.22621.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
        <DefaultLanguage>en</DefaultLanguage>
    </PropertyGroup>

    <PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
        <OutputType>Library</OutputType>
    </PropertyGroup>

I did try to clean, delete obj and bin folders and reinstall the .net maui workload, but without success. Any idea what that is?

EDIT: I think the problem was caused by my try to make the version conditional to non-ios platforms with this:

        <ApplicationDisplayVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'" >7.8.12844</ApplicationDisplayVersion>
        <ApplicationVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios'">2022092726</ApplicationVersion>

Once I moved that to a separate sectio it the build works again.


    <PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
        <ApplicationDisplayVersion>7.8.12844</ApplicationDisplayVersion>
        <ApplicationVersion>2022092726</ApplicationVersion>
    </PropertyGroup>

NPadrutt
  • 3,619
  • 5
  • 24
  • 60

2 Answers2

4

Usually when this happens, your restore command was not called, interrupted, or threw some error. In any case, the issue is not with your VS but your solution.

What you need to do is really simple:

  • Open your solution and clean build. The same error should be thrown
  • Close it and remove the newly created bin and obj
  • Open VS again and go to terminal/cmd and on your solution level call dotnet restore.
  • After that's complete right click on the solution and restore your NuGet packages and your app should now be able to compile and run
halfer
  • 19,824
  • 17
  • 99
  • 186
FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Thanks for your response. I do see the message in the output, that the nuget restored failed. So far I unfortunately didn't manage to make it pass in VS although the `dotnet restore` is always successful. – NPadrutt Sep 29 '22 at 08:36
  • Can you try rebuilding even that should restore nugets – FreakyAli Sep 29 '22 at 09:39
  • I tried that before but without success. But I think I found the solution. I updated my original post with the information. Thanks for your support. – NPadrutt Sep 29 '22 at 12:29
  • step 3: dotnet restore didnt work for me. other then that it should work. This one worked for me https://stackoverflow.com/a/75764034/2500027 – Suchith Mar 17 '23 at 05:30
0

My solution for this is to go to the MAUI Shared in properties and set the build number and display version to the same values across configurations, I can now build.

Don't forget to clean, restore and rebuild

YaRmgl
  • 356
  • 1
  • 6
  • 19