Getting image from Class Library - xamarin.forms

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

Related

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

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.

Use another layer model in .Net Core 3.1

I am a novice in asp .net Core 3.1 programming. Thank you for your help.
I created three layers for my project, one for the core, one for the database and one for the web.
The models are in the ِDTOs folder. Now my problem is to create database tables. I do not have access to the Category model.
How can I solve this problem? I would be grateful if you could guide me in full detail.
The project error image as well as the dependencies on each layer are present in the image.
Due to the problem of uploading photos on the site, I had to upload them to another site
Images link
https://pasteboard.co/JNeXGKJ.jpg
https://pasteboard.co/JNeXsXs.jpg
Your Category class is in the project Pipeland.Core.
Your project Pipeland.Web references Pipeland.Core but your project Pipeland.DataLayer does not.
At the moment, classes in Pipeland.DataLayer (including PipelandContext) can't access any classes in Pipeland.Core (including Category)
Create a project reference to Pipeland.Core in your Pipeland.DataLayer project.
Then add the line:
using Pipeland.Core.Dtos
to the top of your PipelandContext.cs file.
This assumes that your Category class is in the namespace Pipeland.Core.Dtos, which it might not be, but I expect it is.

The type or namespace name 'UWP' does not exist in the namespace 'PdfSharp.Xamarin.Forms'

I am working on a Xamarin.Forms app with PDF features. I am taking my first shot at using PdfSharp (PdfSharp.Xamarin.Forms forked from PdfSharpCore) but finding it's not entirely developer-friendly. I'm trying to use PDFManager and PDFManager.GeneratePDFFromView and was able to do so successfully in my Android project, but it's not working in UWP. The Git page says to init in the UWP App.xaml.cs like this:
PdfSharp.Xamarin.Forms.UWP.Platform.Init();
But when I try this I get the error "The type or namespace name 'UWP' does not exist in the namespace 'PdfSharp.Xamarin.Forms'". Again, I had no problems initializing in Android, but .UWP is not recognized for UWP. I would open this as an issue on GitHub but the option doesn't seem to be there for this repository.
You need to either find PdfSharp.Xamarin.Forms.UWP.dll from the source website directly or download the sample code from that website and build it. Either way this .dll is the file you are looking for. Once you have a copy of this file, use Project>Reference 'Add Reference' to add this .dll to your UWP project. You should find that PdfSharp.Xamarin.Forms.UWP.Platform.Init() is now accepted.
..But of course there is NO guarantee that PdfSharp.Xamarin.Forms will WORK even if you DO successfully add the library ...

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

How do I use functionality available in an embedded jar file?

I'm trying to use GmailSender in my Xamarin Android app. My main project is referencing the binding library, and the binding library has 2 jars - GmailSender 1.1.jar, and mail.jar.
the GmailSender 1.1.jar file is set as an EmbeddedJar in properties, and mail.jar is set as an EmbeddedReferenceJar in properties.
The following image depicts how my project is set up (higher res image: http://i.imgur.com/Xbq5uKa.png)
This is where I got GmailSender 1.1.jar: http://gmailsender.blogspot.ie/
This is where I got mail.jar (renamed from mail-6.0.0.jar) http://www.java2s.com/Code/Jar/m/Downloadmail600jar.htm
How can I get my Xamarin Android app to use GmailSender?
There is a note regarding that issue on Xamarin docs:
Note: Due to bug 6695, when referencing the Java Binding project
directly from a Xamarin.Android project, none of the namespaces,
classes, or other members of the Java Binding project will be visible
in the IDE when working on the Xamarin.Android project. This bug will
be fixed in a future version of Xamarin.Android.
You won't be able to see the bindings unless you reference the generated dll (this is a workaround)
You need to reference the library using the namespace of your binding library. By default, it is probably using "BindingLibrary1" as the root namespace, so try adding a using directive for that namespace.

Resources