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>