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

Question: How to use user controls from another project in published app? #7233

Closed
Iris0905 opened this issue Jun 14, 2022 · 3 comments
Closed
Labels
duplicate This issue or pull request already exists question team-Markup Issue for the Markup team

Comments

@Iris0905
Copy link

I created a shared WinUI 3 class library project for some user controls, and added the shared project as a reference to the main project (unpackaged). It works fine when building and running from visual studio, or running from the bin folder. But after publishing the main project, the published app could not load those user controls anymore. A "XAML parsing failed" exception was thrown.

Looking into the content of the shared project dll in the publish folder, the user control looks for the xaml file like this:

        /// <summary>
        /// InitializeComponent()
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 1.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;

            _contentLoaded = true;

            global::System.Uri resourceLocator = new global::System.Uri("ms-appx:///SharedProject/MyControl.xaml");
            global::Microsoft.UI.Xaml.Application.LoadComponent(this, resourceLocator, global::Microsoft.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Nested);
        }

This SharedProject/MyControl.xaml file exists in the bin folder but is not included in the publish folder. I could get the published app work by copying it over, but it's not a good idea to deliver raw code files to customers. Any suggestions?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Jun 14, 2022
@MEK3DK
Copy link

MEK3DK commented Jun 14, 2022

As reported in many other bugs you can't do it.
I know it is difficult to believe since this has been something you could do for 20+ years in other frameworks, but for now it does not work.

There are many, but examples of other bugs like this one:
How to link WinUI library
WinUI 3 Cant instantiate a UserControl from a location outside the application package or directory (XamlParseException)

@Iris0905
Copy link
Author

Thank you for pointing out the other reported bugs. Yes, it is difficult to believe this is something not in the plan yet... It is definitely an important feature that's supposed to be supported in any UI framework.

@ojhad ojhad added duplicate This issue or pull request already exists team-Markup Issue for the Markup team labels Jun 22, 2022
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Oct 12, 2022
@bpulliam
Copy link
Contributor

If you would like to continue this question, please use one of the example bugs listed above.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

4 participants