Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] .NET MAUI extension always starts with the device target first available on the list no matter what the user selection is #250

Closed
egvijayanand opened this issue Jul 12, 2023 · 18 comments
Assignees
Labels
area-maui fixed triaged The issue has been triaged

Comments

@egvijayanand
Copy link

Describe the Issue

Have installed the .NET MAUI extension.

Opened a .NET MAUI project (dotnet new maui).

Have selected Windows Subsystem for Android (WSA) as the target device.

Though Android is the opted target platform, it always builds and launches the Windows platform as it's the first device target available on the list.

Steps To Reproduce

  1. Install the .NET MAUI extension
  2. Open a .NET MAUI project
  3. Select a device target that is not at the top of the device target list
  4. Try to build and launch the project

Expected Behavior

Expected to build the project and launch in the opted device target.

Environment Information

OS: Windows 11 (v10.0.22621.1928)
VS Code: v1.80.0
.NET MAUI extension: v0.1.34

@egvijayanand egvijayanand added the bug Something isn't working label Jul 12, 2023
@microsoft-issue-labeler microsoft-issue-labeler bot added the area-templates Experiences around the project/item templates label Jul 12, 2023
@maddymontaquila
Copy link

Hi @egvijayanand ! If you try an Android emulator or physical does that work? I'm wondering if this is a WSA issue. When you launch a WSA app it looks just like a Windows app - if you build and deploy for Windows is the app the exact same?

@egvijayanand
Copy link
Author

@maddymontaquila, have validated the build command that is running in the background. Building it for the Windows platform only (-f net8.0-windows10.0.19041.0).

Will try to connect a physical Android device and update the outcome.

@egvijayanand
Copy link
Author

Here's the command from the VS Terminal (username alone removed to protect privacy):

Executing task: dotnet build -t:Build -p:Configuration=Debug -f net8.0-windows10.0.19041.0 -r win10-x64 -p:WindowsPackageType=None -p:CustomAfterMicrosoftCSharpTargets="c:\Users<username>.vscode\extensions\ms-dotnettools.dotnet-maui-0.1.34-win32-x64\dist\resources\maui\MauiVSCodeWindows.targets" -p:_DeletePriConfigXml=True e:\MAUI\NET_8\Preview_6\MauiApp1\MauiApp1.csproj

MSBuild version 17.7.0+5785ed5c2 for .NET
Determining projects to restore...
Restored e:\MAUI\NET_8\Preview_6\MauiApp1\MauiApp1.csproj (in 724 ms).
C:\Program Files\dotnet\sdk\8.0.100-preview.6.23330.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft
.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview ver
sion of .NET. See: https://aka.ms/dotnet-support-policy [e:\MAUI\NET_8\Preview_6\MauiApp1\MauiA
pp1.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MauiApp1 -> e:\MAUI\NET_8\Preview_6\MauiApp1\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\M
auiApp1.dll

Build succeeded.
0 Warning(s)
0 Error(s)

@egvijayanand
Copy link
Author

egvijayanand commented Jul 13, 2023

@maddymontaquila Have tried with a physical Android phone as the target device. But no change in the output. It always builds for the Windows platform and launches it as an unpackaged app. The terminal command is the same as in the earlier comment.

Since the local machine (Windows) is available as the first target, it automatically picks that one, or is it by design to work only with the Windows target in this preview release of the extension?

image

@egvijayanand
Copy link
Author

egvijayanand commented Jul 13, 2023

And found another issue, Selective targeting is not supported.

To narrow down the cause, tried to selectively target Android alone by removing all other target platforms from the project file.

The extension reported it with an error message stating .NET MAUI SDK not found. Refer to the below screenshot.

This is practically a very valid scenario. So, kindly plan to support this as well. Basically, it should look for the UseMaui element and the definition of one or more supported TFMs.

image

@egvijayanand
Copy link
Author

egvijayanand commented Jul 13, 2023

Found another issue, terminal commands using single quote char as a delimiter for the AndroidSdkDirectory property in anticipation of space in the path is causing trouble. The build command is failing. Kindly use double quotes.

Command from the Terminal window (removed username to protect privacy):

dotnet build -t:Run -p:Configuration=Debug -f net8.0-android -p:AdbTarget=-s%20127.0.0.1:58526 -p:AndroidAttachDebugger=true -p:AndroidSdbTargetPort=54183 -p:AndroidSdbHostPort=54183 -p:AndroidSdkDirectory='C:\Users\<username>\AppData\Local\Android\Sdk' e:\MAUI\NET_8\Preview_6\MauiApp1\MauiApp1.csproj

A reference to the issue logged: dotnet/maui#16091

@maddymontaquila
Copy link

Ooooooh interesting. @egvijayanand if you run dotnet workload list does it show maui, maui-android, etc? Then if you run dotnet workload install maui does that succeed? It should be able to target Android without issue. It looks to me like since it can't find the MAUI SDK its just building Windows instead of erroring correctly.

@egvijayanand
Copy link
Author

Yes, @maddymontaquila, have installed the .NET MAUI workload and it's getting listed as well.

Facing this Android build issue in CLI outside of VS Code as well. Seems like the Android SDK directory location delimited by the single quote is creating issues all around. Rather it should be delimited by double quotes which is working fine.

@egvijayanand
Copy link
Author

image

@maddymontaquila
Copy link

It's weird that maui-android isnt listed - could you try dotnet workload install maui-android and see if that works?

@egvijayanand
Copy link
Author

It's weird that maui-android isnt listed - could you try dotnet workload install maui-android and see if that works?

It's there, I clipped the screenshot. It's installed with VS update itself.

Only the MAUI workload is installed manually and Tizen is via VS extension.

image

@maddymontaquila
Copy link

Ahhhh ok sorry! I'm wondering if theres an issue because the workloads are all installed via VS, except for maui. Sometimes they randomly conflict even if it looks "ok". @mcumming will look more when he's back from time off - thank you for reporting!!!!

@egvijayanand
Copy link
Author

A good point to start the troubleshooting would be the scenario where Android SDK is installed in a location that is not the default Program Files folder, as it is here shared with Android Studio as well.

@egvijayanand
Copy link
Author

Hi @maddymontaquila, have resolved the Android build issue by editing the extension.js file made available in the folder %UserProfile%\.vscode\extensions\ms-dotnettools.dotnet-maui-0.1.34-win32-x64\dist.

At a particular location, where the MSBuild properties are collected, for the AndroidSdkDirectory property, Single quotes are replaced by Double quotes as delimiter.

Before:

n.push(`-p:AndroidSdkDirectory='${o.path}'`)

After:

n.push(`-p:AndroidSdkDirectory="${o.path}"`)

Kindly formalize the fix and provide a solution for Selective Targeting, which can be simulated just by commenting on other TFMs.

@mcumming
Copy link

Hi @egvijayanand,
To get back to the original problem in the description. I am mostly interested in Step 3 of your steps to reproduce. Can you describe in more detail how you switched the target platform? Providing screenshots would be very helpful.

Additionally, do you have either the Meteor or Comet extension installed? If so, try disabling them for the current workspace to see if there are possible conflicts occurring.

@mcumming mcumming added needs-more-info Needing more information, waiting on OP and removed bug Something isn't working labels Jul 25, 2023
@mauroa mauroa self-assigned this Mar 19, 2024
@mauroa mauroa added fixed-pending-release triaged The issue has been triaged labels Mar 19, 2024
@mauroa
Copy link
Member

mauroa commented Mar 19, 2024

There's a fix available for this issue that will be published in the next VS Code MAUI pre-release version. We'll proceed to close this issue once that version is available to install.

@mauroa mauroa removed the needs-more-info Needing more information, waiting on OP label Mar 19, 2024
Copy link

github-actions bot commented Apr 4, 2024

This issue has been marked as stale after 14 days of inactivity.@[@mauroa@], could you please take a look?

@mauroa
Copy link
Member

mauroa commented Apr 12, 2024

Closing as fixed on latest .NET MAUI pre release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-maui fixed triaged The issue has been triaged
Projects
None yet
Development

No branches or pull requests

4 participants