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

Programmatically way to Bootstrap Windows Platform in pure C# #8413

Closed
1 task
jvelilla opened this issue Jun 29, 2022 · 5 comments
Closed
1 task

Programmatically way to Bootstrap Windows Platform in pure C# #8413

jvelilla opened this issue Jun 29, 2022 · 5 comments
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup blocked Work that is currently blocked partner/winui WinUI / Project Reunion partner Issue or Request from a partner team platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@jvelilla
Copy link

jvelilla commented Jun 29, 2022

Description

Is there any reliable way to programmatically bootstrap the .NET MAUI windows platform in pure C# without using XAML?

By default, the bootstrap code for the Windows platform uses App.xaml and the code behind App.xaml.cs.

The goal is to learn the bootstrap to initialize the Application in pure C# because I want to use a different programming language and avoid XAML dependencies, initially for proof of concept.

Steps to Reproduce

Git branch with the existing code

To reproduce

  1. Create a default project.
  2. Delete from /Platforms)/Windows/ the files App.xaml and App.xaml.cs.
  3. Create a new class App.cs

with the following code.

using Microsoft.Maui;
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace ExampleMauiApp.WinUI;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public class App : MauiWinUIApplication
{
	/// <summary>
	/// Initializes the singleton application object.  This is the first line of authored code
	/// executed, and as such is the logical equivalent of main() or WinMain().
	/// </summary>
	public App()
	{
        }
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

Expected: Windows bootstrap initialization
Actual output: compile error.

Version with bug

6.0.400 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows

Did you find any workaround?

No response

Relevant log output

Build started...
...
1>CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
1>Done building project "ExampleMauiApp.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Depends on

VS bug #1863736

@jvelilla jvelilla added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 29, 2022
@Eilon Eilon added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Jun 29, 2022
@ericsink
Copy link

ericsink commented Jul 3, 2022

As far I can tell, the short answer to your question is: No.

I've been investigating a Swift projection for WinRT-ish things, including Windows App SDK. I came with the expectations I obtained from past work with the Xamarin Forms flavor of XAML, where everything can be done in pure code without XAML syntax. But for WinUI3 XAML, things are very different.

There is some "magic" associated with the Application class, and it seems to be related to the IXamlMetadataProvider interface. I'm still figuring out how things work.

See also:

microsoft/WindowsAppSDK#2691

and:

microsoft/windows-app-rs#50

@hartez
Copy link
Contributor

hartez commented Jul 12, 2022

The code generated from the XAML includes the missing "Main" method, but you can add your own to the class manually:

static void Main(string[] args)
{
    Microsoft.UI.Xaml.Application.Start((p) => new App());
}

(I've done this before with UWP apps.)

But you'll still run into issues with missing XAML resources for all the controls; some from WinUI, and some supplemental ones from MAUI. I don't know of a way to get those included; trying to create the resource dictionaries manually just throws a COMException.

@jfversluis jfversluis removed the s/needs-verification Indicates that this issue needs initial verification before further triage will happen label Jul 14, 2022
@mattleibow
Copy link
Member

@PureWeen I think you did this with the Fabulous peoples? Basically disable the something and then copy-paste the code from before?

@mattleibow mattleibow added partner Issue or Request from a partner team partner/winui WinUI / Project Reunion blocked Work that is currently blocked labels Feb 7, 2023
@homeyf homeyf added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels Aug 1, 2023
@homeyf
Copy link

homeyf commented Aug 1, 2023

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 5.0. Can repro on windows platform with sample Project.
branch
image

@mattleibow
Copy link
Member

Closing this issue as it is unrelated to .NET MAUI and more related to WinUI and how things are set up.

Please open an issue here: v

@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup blocked Work that is currently blocked partner/winui WinUI / Project Reunion partner Issue or Request from a partner team platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants