Jimmy
Jimmy

Reputation: 2951

Installing .NET 7 preview breaks MAUI build

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

Upvotes: 3

Views: 1923

Answers (3)

Ruina
Ruina

Reputation: 365

My symptoms were:

  1. I could not build a .NET 6 MAUI app and debug on a physical android device after updating to .NET 7. Please note that I also did try with the emulator. However, I did not try to build and run to any other platform.

  2. My errors were:

1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Android is not installed. Please restore and try again.
1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Core is not installed. Please restore and try again.
1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Controls is not installed. Please restore and try again.
1>C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(376,5): error NETSDK1127: The targeting pack Microsoft.Maui.Essentials is not installed. Please restore and try again.

Strange enough, it seems somehow my SDK for Android API 31 somehow was either never installed or was uninstalled during the upgrade. I'm 99% sure it was installed because I have targeted that API for over 3 months now. Well, it turns out it wasn't, so I installed the API through the Android SDK manager, and now it works.

Upvotes: 0

Jimmy
Jimmy

Reputation: 2951

  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"

Upvotes: 1

Gerald Versluis
Gerald Versluis

Reputation: 34013

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://learn.microsoft.com/dotnet/core/tools/global-json

Upvotes: 3

Related Questions