My team has built a Xamarin.Forms application using VS2017. We are using a Shared project because one of our core functionalities requires ESRI mapping, and ArcGIS Runtime for Xamarin does not support anything but Shared projects at this time.
The next app that my boss wants should be fairly quick to develop if I can use the existing code we've already written for the first app. However, I don't see any way that I can reference that code from another project. I have tried adding a new UWP project to the existing one, but then I have to add all the same NuGet packages, 90% of which are unnecessary to this new project. On top of that, it won't actually compile correctly since the App.xaml is different.
I've searched all over trying to find a solution to this, and haven't come up with anything. PCL is not an option, nor is .NET Standard. Is there any way to accomplish this?
Related
I work with Xamarin.Forms in Visual Studio since a few years, and updated my IDE recently (VS v. 16.3.7). Now I realized something is missing: the Shared Project option.
When i go through the Wizard to create a new project the question if I want to use Shared Project or PCL(or NetStandard) is now missing (see screenshot below from VS 2017)
I do know that you can still create a Shared Project and add an iOS and an Android project manually, but this is just too cumbersome. My question really is: Is there a reason why Microsoft went on to push the PCL/NetStandard above the Shared Project strategy?
I am specially confused about this decision since already back in 2016 #miguel.de.icaza declared his favorite option (for most cases) was the Shared Project strategy:
https://tirania.org/blog/archive/2016/Jan-22.html
For me, the PCL is just too cumbersome for most uses. It is like using a canon to kill a fly. It imposes too many limitations (limited API surface), forces you to jump through hoops to achieve some very basic tasks.
I have installed VS 2017 15.9.14, on this version, Portable Class Libraries (PCLs) are deprecated. You could use .NET Standard instead. On VS 2019, the default is .NET Standard.
On Microsoft document, MS recommend .NET Standard 2.0 libraries over Portable Class Libraries.
For more, please refer to the MS docs. https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/code-sharing
My question really is: Is there a reason why Microsoft went on to push the PCL above the Shared Project strategy?
For MS announcement, PCL is deprecated, you could not find that when you create the project.
You could create the Shared project by File > New > Project > Shared Project template.
For more details, you could check the link below. https://learn.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/shared-projects?tabs=windows
Updated:
Is there a reason why Microsoft went on to push the >NetStandard< above the Shared Project strategy?".
For the old version of VS 2017, .Net Standard is an option of Shared Project strategy.For the latest version of VS, MS use .Net Standard as the default for Sharing Strategy.
Is there any doc where MS states why Shared Project is now deprecated/not available in the Xamarin.Forms project wizard?
PCL is deprecated. Shared Project is still in use, in my answer, I provide the second link about how to create the shared project.
Summarizing and adding to the answer by #WendyZang-MSFT:
I started a project using the Shared Project strategy around 4 years ago, and until now i have not found any issue/problem specific to it that would make me consider moving to .Net Standard.
Recently i went into the trouble of localization, and even that was possible using Shared Project without much hassle.
As mentioned above, after i saw that the latest version of Visual Studio 2019 was not offering the possibility of creating a Xamarin.Forms App as a Shared Project i got a bit worried thinking that i should migrate my solution. But the time hast passed by, and i just realized that MS encourages the use of .Net Standard, but Shared Project remains also a valid approach.
I've created two different Xamarin.Forms solutions from templates. The first one is created with Prism template pack (version 2.0.5) the other one is created with the built-in Xamarin template that comes with Visual Studio 2017 (15.5.0 Preview). Both solutions utilize .net standard 2.0 and build fine on all three platforms. Now to the confusing part. As seen in this image:
the Android-project references of the two solutions is quite different. Why don't the first project need all the references of that the second do?
Because the Prism Template Pack is using the CopyNuGetImplementations feature of NuGet. This means that your projects do not need to add the references again. They will automatically get any NuGet references you have added to the main XF project. Much easier to manage.
I'm developing a xamarin forms class library (Custom Component) that targets (Windows, Androi and IOS) platforms "this library should be added to an existing Xamarin forms Portable project as DLL reference" and want to add a UI control and use it's native functions from inside the library. Custom renderers can't be added in PCLs so Can anyone help on how to access the control's native functionality?
You can start from scratch on your by following this piece of documentation by Xamarin on how to build NuGet packages. Then just make sure you build them without too much references and test them in your sample projects.
But to make your life a lot easier have a look at this Visual Studio extension by James Montemagno. It installs some project templates for you so naming is consistent and you have the basics already setup to start building your reusable code.
I'm trying to build an Android and iOS app with Xamarin using a shared PCL library. I'm following the tutorial on the Xamarin website [1].
I have created my PCL solution, which currently doesn't do anything, and I'm now trying to reference it from another Android solution.
The documentation indicates I should use References and then select Projects. However, when I do this, I can't either see or find a way to add my PCL library project as a reference.
How can I add my PCL library solution as a reference in another solution?
[1] http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/introduction_to_portable_class_libraries/#Using_PCL
A solution is just a container for one or more projects. One project can be included in multiple solutions. By including multiple projects in one solution you can reference them from one another, which will allow them to automatically build/update their dependencies when needed. You can add a new project to an existing solution by doing "Add New Project" in the solution explorer - you don't have to create a complete new solution for each project.
My background is c#, .net, and Visual Studio.
I've been trying to get to grips with Cocoa development, but am finding it hard to find information about certain things, maybe because I'm coming in from a Visual Studio perspective.
A few questions:
What's the difference between a "Framework" project, and a "Library" project in XCode?
What are the consequences of choosing "dynamic" or "static" for your project when starting a new XCode project. Can this be changed later on? does it affect the contents of the project?
Does XCode have the concept of a "solution" with various projects like Visual Studio? If so, how do you reference projects with each other which are in the same solution in XCode?
Is it even right to approach a Cocoa project in the same way as a .net one. For example, if I was going to build a simple image manipulation app, I'd start with the core library, which could be referenced in a winforms, silverlight, or an MVC frontend app. How does that organisation work in XCode?
A Framework project builds a Framework, and a Library projects builds a Library. A Framework (.framework) is the means by which a library and its associated header files are bundled together in one package (similar to the way an executable and its sundry files are bundled together into a .app package). If you're building a library which you intend to use in multiple Cocoa projects, or distribute to other developers for that purpose, a Framework is probably the most convenient way to do so.
A static library (.a) is analogous to a .lib file in Windows. It's compiled code which you can link into your executable. A dynamic library (.dylib) is analogous to a .dll in Windows. It's compiled code which can be dynamically loaded by your executable. You can change the output from one to the other after you create it (see the Mach-O Type field under Linking in the Build tab of Project Info. However, there are probably other settings which would vary between the two. My advice would be to decide which you want to make, make the project for that, and don't change it.
Yes, you can build multiple things from an Xcode Project. An Xcode project is exactly analogous to a Visual Studio Solution. What Visual Studio calls Projects, Xcode calls Targets. So an Xcode project can have multiple targets. Say, one for a Framework, one for an application that uses that framework, one for a suite of unit tests, etc. Make yourself an Xcode project, and right click Targets->Add->New Target, and you can play around with it. Each Target has its own build settings, files, etc.
My background is more the MFC/C++ side of the Visual Studio house than the .NET/C# one, but to my knowledge, what you describe is possible, even desirable, in Xcode, sure. My projects have thus far never been large enough, nor the code amongst them common enough, to bother having a separate library for core functionality, but there's no reason you couldn't do that.