Xamarin iOS - How do I include dependencies when binding libraries? - c#

I have an Obj-C native library libCMX.a that I wish to create C# bindings for, but the library has multiple dependencies, e.g. JASidePanels with a couple of .m and .h files.
How can I include these in the Xamarin binding project so they are linked correctly into the resulting DLL?
I know I can specify Frameworks in the LinkWith attribute, but how do I include pure code dependencies in form of main and header files?
EDIT: The library is proprietary (Cisco CMX SDK), I do not have access to the source code.
EDIT 2: The library is part of a framework (CMX.framework), from which I have extracted the extensionless archive and renamed it to libCMX.a to match default library naming for Xamarin.

You can reference multiple native libraries in your binding project, the combined set of libraries will be linked into your application.
You only need to surface the APIs for libraries that you want to invoke/call. For the rest, just include the binary dependencies.

You will need to compile those into the static library (libMyLibrary.a) you are binding to C#.

Related

Why do C# and VB projects have a different manifest resource structures?

My project is a C# NET Framework 4.8 web app that utilizes a Resources folder (with files built as Embedded Resources) to fetch templates at runtime.
Recently I converted it from VB to C# using a very nice Code Converter. While it worked fine, now it seems the structure of the manifest resources has changed, as shown by Assembly.GetManifestResourceNames().
For example, what used to be App.IssueNotification.html is now listed as App.Resources.EmailTemplates.IssueNotification.html .. matching the folder structure in the solution, but forcing me to make changes.
My questions are
What is this VB/C# difference actually called? Is there documentation?
Is there a setting or flag to use the "flatten" resource names like VB does so I don't need to update my code?
You can use vb library inside C# projects, is not an option for you to do it so?, this way you would not need to convert the project you can just easily access to it as an any .dll (library)

How to compile localization DLLs (MyLibrary.resources.dll) into a single DLL?

Using C# .NET with COM interop in VS2012, I'm developing a common library for use in several other programs. To keep the integration simple, I would like to keep the entire library down to one DLL. One of the features of this library is localization. It has string tables with messages in multiple languages, each language having it's own ResX file.
Presently, a MyLibrary.resources.dll is being created for each language and placed in its own subdirectory, like this:
Release\MyLibrary.dll
Release\ja\MyLibrary.resources.dll
Release\fr\MyLibrary.resources.dll
What I want to see is just this:
Release\MyLibrary.dll
Here are my current ResX settings.
I have tried using ResXFileCodeGenerator and GlobalResourceProxyGenerator for the "Custom Tool" generators. I also tried a few options for "Build Action" including Compile, but so far only Embedded Resource works. Other than that I'm not sure what else to try or if I'm on the right track. There aren't really that many settings to work with.
I am aware that there are a variety of tools that may work to do this after building the DLL, but I'm looking for a compile-time solution. Third party tools are challenging from a maintenance standpoint -- I will not be the only one updating this library.
There are two main ways of embedding libraries into a single DLL or executable. The first uses ILMerge, combines all assemblies as if it was a single assembly; the second is dynamically loading dependencies from embedded resource(s) at runtime (offers a bit more flexibility, but has its own set of pros and cons). The sample project is intended to be portable (the only dependency is Powershell -- all required libraries are included in the project).
It's important to know the difference between the two techniques. I've written articles outlining both approaches with a sample project on github for both approaches.
Articles:
Assembly Loading: Combine Assemblies & Executables Using ilMerge
AND
Assembly Loading: Dynamic Assembly Loading & Compression
Sample Project:
Application Demonstrating Both ILMerge and Runtime Loading of Embedded Assemblies
If you have any questions regarding either approach, don't hesitate to get in touch. I'll gladly refine the posts based on your feedback.

No implementation file was provicded for the .winmd file

I have a warning when I build my Windows 8 App project in VS2012:
No implementation file was provided for the .winmd file 'C:\Users\luke\LApp\LApp\bin\x86\Debug\Bing.Maps.winmd'. To generate registration information in the app manifest, specify the 'Implementation' metadata on the .winmd reference item in the project file.
I don't really know what other information to provide. I've Googled and it doesn't provide any relevant results. It gives a link to this: http://msdn.microsoft.com/en-us/library/hh708954.aspx but I'm not sure it is the correct thing. I'm pretty sure I have the correct references:
It is a C# project. I used NuGet to add the Bing Maps SDK and it works in my app - I can drag on a map interface and use it in the app. This is just a warning that shows up when building and I have no idea how to get rid of it.
Any help appreciated, thanks.
Is your project a c# project?
Usually WinRT components implemented using .NET are just .winmd files. Both interface and implementation are contained within the .winmd file. Whereas native components (those written in C++) will have separate .winmd and .dll files for interface and implementation respectively.
It would be helpful if you could provide more details about your app project and the repro steps.

Including xib(s) / nib(s) in a MonoTouch Binding project

I'm trying to create a re-useable MonoTouch library that contains Views defined in a xib, and Controller code written in Objective-C.
I have created a static Objective-C library that contains the relevant controller code with all the outlets declared.
A static *.a library obviously can't contain xib/nib data (if this is possible can someone please let me know), so I can't embed the xibs/nibs in this library.
I have created a 'MonoTouch Binding Project' that defines the relevant wrapper classes.
This is where I would ideally also embed the xibs/nibs, and have them included in the app bundle of any final project that links this dll.
Now looking at what a 'MonoTouch Library Project' does with xibs - it compiles it to a nib using ibtool, and then embeds it as a resource in the resultant library dll using the /res option of smcs. I'm assuming this is triggered because the xib file is marked with a "InterfaceDefinition" build action in the project.
However a 'MonoTouch Binding Project' has no "InterfaceDefinition" build action. Is this possible at all using a MonoTouch Binding Project?
I haven't tried it yet, but I'm assuming I could get it working manually by combining what the Library project does with ibtool and smcs /res and what the Binding Project does with btouch and smcs. But I'd rather avoid this, I'm enjoying the lack of Makefiles lately.
Xamarin/MonoTouch team - any plans to add this to Binding Projects in the future? Any way to force it to work currently?

Linking statically in C#

I'm working on a module for a CMS. This module is distributed as a class library DLL.
I have several utility libraries I'd like to use in this module. Is there anyway I can link these libraries statically so I won't have to distribute several DLL's (thereby distributing my utility libraries separately)?
I would like to have only one DLL.
You can merge your many DLLs with ILMERGE:
http://research.microsoft.com/~mbarnett/ILMerge.aspx
Haven't tried it myself. Hope it helps.
Download here:
http://www.microsoft.com/downloads/details.aspx?familyid=22914587-B4AD-4EAE-87CF-B14AE6A939B0&displaylang=en
Brief Description (from download-page)
ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output. See the accompanying documentation for details.
If you don't want to use ILMerge, see this page:
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
editor's note: Jeffrey Richter advices to put your dlls into exe file as resources (For each DLL file you add, display its properties and change its “Build Action” to “Embedded Resource.”). Then a custom class loader is needed to make the executable work (At runtime, the CLR won’t be able to find the dependent DLL assemblies, which is a problem. To fix this, when your application initializes, register a callback method with the AppDomain’s ResolveAssembly event).
Be sure to change the resourceName string to point to your actual resources. (e.g. change AssemblyLoadingAndReflection to your project name.)
The short answer for this is no!
You can not link in a dll during compilation.
I don't know if there is some subtle way to do this, but you would probably have to distribute the dlls along with your cms.
The best way to do this is to make some kind of re-distributable.

Categories