microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.16k stars 666 forks source link

Provide a way to run winui apps from dotnet cli #7331

Open ziaulhasanhamim opened 2 years ago

ziaulhasanhamim commented 2 years ago

After MAUI now it's possible to build cross-platform GUI apps with .net. But when building apps with MAUI Blazor or MAUI Comet many people prefer vs code over vs 2022. With MAUI it is possible to build with dotnet cli for all the platforms except windows. Because building winui apps is not supported with cli. But why not? This is a great time to support it. dotnet build -t:Run -f net6.0-windows

lhak commented 2 years ago

Using dotnet run works for me for an unpackaged winui app

ziaulhasanhamim commented 1 year ago

@lhak Really you are able to run winui 3 apps from cli? How?

lhak commented 1 year ago

@ziaulhasanhamim Create a new WinUI project (empty project with separate packaging project). Then add the following lines to the project file:

<WindowsPackageType>None</WindowsPackageType>
<EnableMsixTooling>true</EnableMsixTooling>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>

Dotnet run (in the directory with the project itself, not the solution) shows some warning message about running as AnyCPU, but the app still starts.

ziaulhasanhamim commented 1 year ago

Do have any idea if it works with MAUI?

ajsuydam commented 1 week ago

Hey team, our use case for an internal app I'm building with MAUI is being significantly impaired by this. Please, please fix or provide a workaround. I've been fighting Windows for days to get something working, and I need to move on.

lhak commented 1 week ago

There currently seems to be a bug in the winui build scripts that still set the runtime identifier to win10-platform instead of win-platform when in AnyCPU configuration. To workaround that, you can addx64 (or the specific platform you want to use) to the csproj file.

ajsuydam commented 1 week ago

@lhak could you be a little more specific? I believe I am already doing that - I build in both Debug and Release with the platform set to x64, and this is my pubxml: (there are some missing open tags since github formatting is weird) xml version="1.0" encoding="utf-8"? Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> PropertyGroup> PublishDir>bin\x64\Debug\net8.0-android\publish\</PublishDir> PublishProtocol>FileSystem</PublishProtocol> RuntimeIdentifier>win10-x64</RuntimeIdentifier> Platform>x64</Platform> Configuration>Debug</Configuration> TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> PublishSingleFile>false</PublishSingleFile> PublishReadyToRun>false</PublishReadyToRun> SelfContained>True</SelfContained> PublishAppxPackage>true</PublishAppxPackage> AppxPackageDir>C:\Users\<username>\temp\Packages</AppxPackageDir> /PropertyGroup> /Project>

lhak commented 1 week ago

@ajsuydam What error do you get? The issue I have observed is that "dotnet run" does not accept any parameters and reverts to AnyCPU configuration. The winui build scripts then set the runtime identifier to win10-platform (I think platform is derived from the system you are currently running on). This worked in the past, but does not work anymore with .net 8 (it should set it to win-platform) unless you set the UseRidGraph parameter to true.

So the workaround I have found is to set the Platform parameter directly in the csproj to avoid the AnyCPU configuration. Of course, this is not viable if you want to build for other platforms as well.

ajsuydam commented 1 week ago

@lhak Where are you running dotnet run from? I get a myriad of errors depending on the answer to that question.

lhak commented 1 week ago

@ajsuydam I used "dotnet run" from the commandline