How to use .NET 6-windows and .NET 6 targets in one library - uno-platform

I've segregated my WinUI 3 application into different layers: Application, Infrastructure, Presentation etc.
And all the projects have targets: net6.0-windows and I want to move it to the Uno Platform.
So, I've added a new target: net6.0
And at this moment the problem arises:
Type [WinUI] component already defines a member, called InitializeComponent or some problems with binding.
Is it possible to make such type of library with targets to net6-windows and net6.0?

For the Windows app project itself, you need to use net6-windows, as that provides additional dependencies specific to Windows app projects. All other libraries (non-app projects) can then use net6.0.
Regarding the specific error message, you are getting, the reason might be the generated files have some kind of conflict - you can try deleting the obj and bin folders and rebuild.
The easiest way to make existing Windows app support Uno would probably be to create a blank Uno solution and then migrate the code there (as the solution has already the required setup for platform-specific projects prepared and you can then just add your code.
Uno also provides templates for cross-targeted libraries, so you might be able to use similar approach. The one linked is for "UWP" solution however, so to make it WinUI, you would need to switch from uap10.0.18362 to net6-windows.

Related

Do WinUI applications need runFullTrust to publish to the Windows Store?

I recently took a stock WinUI template, added my old UWP C# code, recompiled and tried to publish. The Windows Store Application Submission warns me that I shouldn't use the runFullTrust setting:
We detected the use of one or more restricted capabilities in your Package.appxmanifest file. You must request approval to use restricted capabilities by providing more information below. Please include as much detail as possible. Learn more
If you don't need to declare these capabilities or added them in error, you can remove them from your Package.appxmanifest file and then upload the updated package(s).
but here's what I got from the template:
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
I tried removing it, but it wouldn't even compile. Can anyone tell us the backstory of this flag, why it's needed in WinUI but not UWP, and how we get around the Windows Store Submission error.
Do WinUI applications need runFullTrust to publish to the Windows Store?
Yes.
A WinUI 3 app uses the full-trust desktop app model. A UWP app runs in a sandbox.
As stated in the docs, distributing your packaged desktop (WinUI 3) app requires you to answer "a few extra questions as part of the submission process. That's because your package manifest declares a restricted capability named runFullTrust, and we need to approve your application's use of that capability."
So you should provide information about why you need to use the runFullTrust restricted capability when you publish the app. You could for example explain that it's a desktop app and what it does.
WinUI 3 does not need to be full trust, but you still need to declare any UWP-like capacities you are using.
Here is a tutorial that shows how to do it.
https://nicksnettravels.builttoroam.com/winui-appcontainer/

When referencing a .Net Standard project within a Xamarin solution, does all the code from the project get compiled into the app

Apologies if this sounds like a silly question. I'm not very experienced with how things are linked/bundled/assembled under the hood.
Before I begin, I'd like to say that I've tried reading documentation (such as https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/code-sharing) to find the answer, but was unable to.
If I have a Xamarin.Forms solution and I reference a .Net Standard project:
Question 1: Does all the code from this project get compiled and included into the app such that it may be disassembled later, or is it only code from classes that I actually make use of that gets included?
Bit more elaboration:
For example, I may have a School class that expects an IStudent (inject via DI), and a Student class that implements IStudent. Both of these exist in the .Net Standard project that I reference in the Xamarin.Forms project. However, if I only actually make use of the Student class (by registering it with type IStudent in my IoC container), will the code from School get included in the built app as well?
Question 2: If all the code from the project does get included, is there a way to forcefully specify which classes to include/exclude by way of some configuration setting, attributes, 3rd-party library, or something else?
As far as i know everything in the NETStandard project get compiled and shipped with the app.
If you want to remove unused code from compiled assemblies you have to use the linker.
To link everything, you have to select "Sdk and User Assemblies".
The linker tries to dont strip away mthods and fields you are using, but often is too aggressive (for example, methods referenced only by reflection will be stripped).
Luckily there are few methods where you can fine-tune the linker behaviour and make it work. Some link to elaborate on:
Linker in iOS and Android
https://learn.microsoft.com/en-us/xamarin/ios/deploy-test/linker
https://learn.microsoft.com/en-us/xamarin/android/deploy-test/linker
Official doc about the linker config:
https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker
Useful blogposts:
https://xamarinhelp.com/xamarin-linker/
https://medium.com/#harrycblum/reduce-your-xamarin-app-size-with-linking-26247edc87f6

Getting image from Class Library

I am doing a refactor of my Xamarin project, in which I want to build nuget-packages for my platform specific projects.
And since you can't make your "App.Droid", "App.iOS" and "App.UWP" into nugets I am using class libraries for this.
My problem is when I put my images (ordinary *.png-files) in my UWP-class library it won't work. It is working in both iOS and Android.
So my question is if anyone knows if this is possible, and if so how?
My current setup is as follows:
My UWP-project is named "App.UWP". This is the project i build and the project has the "App.xaml" and "MainPage.xaml".
I then created a "Class library (Universal Windows)" named "Company.Mobile.Core.UWP".
My "App.UWP" is referencing "Company.Mobile.Core.UWP".
I know I have a working connection between the two. My Custom renderers are in the "Company.Mobile.Core.UWP"-project and not in "App.UWP" and is working fine.
Cheers,
Tobias

Why do I need to deliver DevExpress.Printing.v14.2.Core.dll

I have implemented a WPF application using DevExpress controls.
When I was finished, I optimized my references in Visual Studio (using Resharper). I have the following references left:
DevExpress.Data.v14.2.dll
DevExpress.Mvvm.v14.2.dll
DevExpress.Xpf.Core.v14.2.dll
DevExpress.Xpf.Grid.v14.2.dll
DevExpress.Xpf.Grid.v14.2.Core.dll
DevExpress.Xpf.Ribbon.v14.2.dll
When starting the application on a clean OS, it crashes. With Process Monitor, I find that it is looking in 10 different places for DevExpress.Printing.v14.2.Core.dll and cannot find it.
That DLL is 3 MB in size and I'd like to avoid to deliver it, if possible.
Dependency walker seems to not work well for .NET.
I have read DevExpress about required libraries, but that is for XtraReports, which I'm not using in my application.
Why does my application look for that DLL if it is not referenced?
Found the answer using JetBrains dotPeek:
DevExpress.Xpf.Core.v14.2.dll and DevExpress.Xpf.Grid.v14.2.dll both have a reference to DevExpress.Printing.v14.2.Core.dll.
Your application contains the DXGrid. Thus, according to the DXGrid's required Redistributable Assemblies list, the DevExpress.Printing.v14.2.Core.dll assembly contains classes that allows to implement the functionality for DXGrid's printing and exporting based on DXPrinting library.

Sharing code between Flex and AIR

As you know, we could build a RIA application based on flex. Also, we could build an desktop application based on AIR. I have a question, If we want to build web & desktop application simultaneously. Could we use the same codes to ship our production to web & desktop?
If you design your application for it, you should have no problems in sharing 99% of your codebase between your Flex and AIR builds.
You will need a separate application MXML for the Flex / AIR versions as AIR uses a WindowedApplication and Flex uses Application
You will need to abstract your usage of any AIR-only APIs. That is, any class, property or method marked with the AIR-only icon (
) in the Online Documentation. You might find this process easier if you are using a Dependency Injection container like Swift Suspenders.
Alternatively, you can split your service definitions into two different source trees. This would result in your AIR project and Flex project sharing one source path, but also having their own source path. This way, code that accesses com.application.MyService would be shared across AIR and Flex but the implementation of com.application.MyService would differ depending on which 'service source path' was being used.
You may find it useful to configure each build with a compiler flag like -define+=CONFIG::AIR. This allows you to use conditional compilation so that you can compile the same file for both builds, but include specific code for the AIR build.
Here is an exmaple of conditional compilation:
public function getMyService() : IMyService
{
CONIFG::AIR
{
return new MyServiceThatUsesAnAIROnlyAPI();
}
return new FallbackServiceForFlex();
}
Unfortunately there is no way to 'negate' a conditional flag (ie. !CONFIG::AIR) so you either need to be smart about your usage of it, or include two flags (CONFIG::AIR and CONFIG::FLEX)
I'm surprised no one said it yet, but this is how I would do it:
Create a library project. this project will include all your
shared code.
Create a Flex project for web deployment
Create an AIR Project for AIR deployment
Both the Flex and AIR projects can reference and use code in the library project. The AIR project can use AIR specific functionality without affecting the web project.
If you need to perform different actions differently based on whether using the web project or the AIR project, you can create interfaces in the library project and implement them in the main project to use the respective APIs.
yes, you can do it.
there are some conditions you have to control in code.
Keep in mind, if the application is also a flex app, then it will be a single window app.
for every project I make needing this I create 3 projects
code base (the main control is a group or a canvas)
flex exporter => when you build this you will end up with a flex application
it has a control from #1 inside the main application
air exporter => when you build this you will end up with an Air app
it has a control from #1 inside the main window.

Resources