Installing .NET 7 preview breaks MAUI build

Viewed 73

Since installing the .net 7 preview I can no longer build .net maui projects. I've uninstalled the preview and deleted the bin/obj files but still can't debug. The error's i'm getting are:

'{directory}/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. 
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets    267 

After trying dotnet restores and uninstalling/reinstalling .net components i now can't even click debug and get the error: visual studio unable to start debugging the startup project cannot be launched...

Update I uninstalled and reinstalled visual studio and .net and got it working, momentarily. But now I'm getting the same errors again. I close and re-open Visual Studio or uninstall/reinstall components and then maybe get a different error like this one:

Manifest file at 'obj\Debug\net6.0-android\android-arm64\staticwebassets.build.json' not found. C:\Program Files\dotnet\sdk\6.0.401\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets

Or no option to debug android at all: no android option

I think this is related to my other open question: .Net MAUI Blazor - can't click anything - "No package ID ff found for ID 0xffffffff", android

2 Answers

I think .NET 7 RC1 will be the first version that also has the .NET MAUI workload installed.

You can have .NET 7 installed and still work with .NET MAUI (which will then operate on .NET 6) by using a global.json file.

In the working directory of you .NET MAUI project open a command-line and type: dotnet --list-sdks. From the resulting list pick the latest .NET 6 version. Let's say that is 6.0.400, but it can be different for you.

Now in the same directory still, type: dotnet new globaljson --sdk-version=6.0.400.

This will create a file global.json that pins the version of .NET to be used to the version you specify.

For more information on the global.json file, read here: https://docs.microsoft.com/dotnet/core/tools/global-json

  1. Downgrading from 6.0.401 to 6.0.400 as suggested here seems to be a solution
  2. Then I had to manually update the gloabl.json file to point to 6.0.400.
  3. Then I had to open & close visual studio and do a dotnet restore.
  4. Then I could debug on windows (be sure the framework selected in the dropdown is (net6.0 windows) otherwise you'll get that popup.

However I still can't debug android as there's no selectable option and when I manually run

dotnet run-f:net6.0-android -c:Release

I get there error: error MSB4044: The "AndroidSignPackage" task was not given a value for the requried parameter "KeyPass"

Related