Xamarin is a cross-platform technology that makes it possible to build native mobile apps for Android, iOS, and Windows Phone using C# and a shared codebase. Like its younger siblings NativeScript and React Native, it allows development teams to build mobile applications using the skills they already have, and spend less time writing code for each platform.
The issue occurs in Visual Studio for Mac when trying to create a new Xamarin Forms Blank project. As soon as the project is created there are already errors: Could not install package 'Xamarin.Android.Support.v4 23.3.0'. Here’s another quick resolution to one of the most annoying issues I’ve faced in working with Visual Studio for Mac When creating a brand new, out of the box, Xamarin.Forms project, it didn’t work. This has been a common trend for Xamarin/Microsoft over the last year or so as they roll out. I'm currently working on a Xamarin.Forms project named ABCD, using macOS Sierra v10.12.6 and Visual Studio (VS) for Mac v7.3.2 (the set up steps are detailed here.
If you haven’t tried Xamarin yet, now is a great time to get started! Earlier this year, Microsoft bought Xamarin and made it free (and open-source). You can build Xamarin projects on Windows (using Visual Studio), or Mac/Linux (using Xamarin Studio).
I’m excited to dig into Xamarin because mobile apps need authentication and authorization, which Stormpath makes easy. We already have rich SDKs for .NET and ASP.NET, as well as SDKs for iOS and Android separately, but a Xamarin-specific SDK could provide even more value and make it super simple to secure your apps. It’s something I’m currently digging into, so stay tuned!
In this tutorial, I’ll show you how to use Visual Studio and Xamarin to build a basic app for iOS and Android — even if you’ve never done any app development before!
Setting Up Visual Studio and Xamarin
If you don’t have Visual Studio 2015 installed, download the free Community Edition from Microsoft. If you already have Visual Studio, make sure you have the latest update (Update 3 at the time of writing).
You’ll also need to install some optional components for Visual Studio. If you’re setting up Visual Studio from scratch, make sure these items are selected:
If you have an existing installation, you can verify that these components are installed by opening the Control Panel, choosing Uninstall or change a program, and selecting Microsoft Visual Studio 2015. Follow the installation wizard to make sure the above items (at a minimum) are checked.
Once you have the tools set up, you’re ready to create a Xamarin project!
Xamarin vs. Xamarin.Forms
The Xamarin SDK provides bindings to the platform-specific APIs on each mobile platform, so you can call Android or iOS APIs from C# code. This allows you to build native apps using C#, but you still need to design the UI separately for each platform.
Xamarin.Forms is an additional layer on top of the Xamarin SDK that makes it possible to build your UI once (in XAML markup) and let Xamarin do the hard work of translating it into the appropriate UI elements on the target platform. You can drop down to the Xamarin SDK level and interact with the platform APIs if you need to.
Should you use “raw” Xamarin, or Xamarin.Forms? It depends on what you are building:
If you’re building an app that needs little platform-specific functionality or custom UI, go with Xamarin.Forms. This is a good choice for straightforward readonly='><?xml version='1.0' encoding='UTF-8'?><ContentPage xmlns='http://xamarin.com/schemas/2014/forms' xmlns:x='http://schemas.microsoft.com/winfx/2009/xaml' x:Class='HelloWorldApp.HelloWorldPage'> <ContentPage.Padding> <OnPlatform x:TypeArguments='Thickness' iOS='20, 40, 20, 20' Android='20, 20, 20, 20' WinPhone='20, 20, 20, 20' /> </ContentPage.Padding> <ContentPage.Content> <StackLayout VerticalOptions='FillAndExpand' HorizontalOptions='FillAndExpand' Orientation='Vertical' Spacing='15'> <Label Text='Enter your name:' /> <Entry x:Name='NameEntry' Text='Jane Doe' /> <Button x:Name='SayHelloButton' Text='Say Hello' Clicked='SayHelloButton_OnClicked' /> </StackLayout> </ContentPage.Content></ContentPage>2 4 6 8 10 12 14 16 18 20 22 | <ContentPage xmlns='http://xamarin.com/schemas/2014/forms' xmlns:x='http://schemas.microsoft.com/winfx/2009/xaml' <ContentPage.Padding> iOS='20, 40, 20, 20' WinPhone='20, 20, 20, 20'/> <ContentPage.Content> HorizontalOptions='FillAndExpand' Spacing='15'> <Entryx:Name='NameEntry'Text='Jane Doe'/> <Buttonx:Name='SayHelloButton'Text='Say Hello'Clicked='SayHelloButton_OnClicked'/> </ContentPage.Content> |
This XAML code creates a basic layout containing Label, Entry (text box), and Button controls. The control names (specified with
x:Name
) will be used to refer to the controls in code.The
Clicked=
attribute on the Button element wires up the button click event to a handler called SayHelloButton_OnClicked
, which doesn’t exist yet (but it’s about to!)Open up the code-behind for the XAML file by expanding it in the Solution Explorer and double-clicking on the
HelloWorldPage.xaml.cs
file.Replace the generated C# code with the following:
2 4 6 8 10 12 14 16 18 20 | using Xamarin.Forms; namespaceHelloWorldApp publicpartial classHelloWorldPage:ContentPage publicHelloWorldPage() InitializeComponent(); privateasync voidSayHelloButton_OnClicked(objectsender,EventArgse) varname=NameEntry.Text; await DisplayAlert('Greeting',$'Hello {name}!','Howdy'); } |
Looks familiar, doesn’t it? The
SayHelloButton_OnClicked
method will run when the SayHelloButton
is clicked on the XAML page. First, the value of the textbox is assigned to the name
variable, and then the DisplayName
method is called to display a modal popup on the device.There’s one more thing to do before you’re done: telling the app to use the new page. In
App.cs
, replace the constructor method with this:2 4 | { } |
That’s it! Your new Xamarin app is ready to go.
Testing Your Xamarin App on Android
If you have the Visual Studio Android Emulator installed, testing the Android version of your Xamarin app is simple. In the Visual Studio toolbar, pick the HelloWorldApp.Droid project and choose an Android device to emulate. Then, click the green Play button to start the emulator.
The Android emulator can be slow to load, so give it some time. If everything builds properly, you should see your app running on Android.
![Xamarin Forms Project In Visual Studio For Mac Xamarin Forms Project In Visual Studio For Mac](https://www.techierathore.com/wp-content/uploads/2016/04/NewProjectXS-2.png)
Testing Your Xamarin App on iOS
Testing your Xamarin app on iOS is a little trickier, because it requires a Mac to provide the emulator. If you have a Mac handy, follow the official instructions to set up the Mac agent and connect it to Visual Studio. Then, pick the HelloWorld.iOS project, and switch the architecture to iPhone Simulator. Choose a device version and click Play.
After the project builds, the simulator will launch on the Mac.
Next steps
This tutorial only scratches the surface. There’s plenty more you can do with Xamarin! Here’s some further reading:
If you’ve built something cool with Xamarin, let me know in the comments or on Twitter @nbarbettini!
Last year at Build, we launched Visual Studio for Mac, our native macOS IDE for developers building cloud, web, and mobile applications using .NET. Updates have been rolling out at a steady pace ever since, and we’re excited to announce the release of Visual Studio for Mac version 7.5. We have also continued to bring more Visual Studio 2017 code to the Mac.
Our mission has always been to delight developers, and we have something for everyone in this release. How to open pdf files in silhouette studio for mac. You can get started by downloading the new release or updating your existing install to the latest build in the Stable channel.
Here are some of the features we’re most excited to share with you:
- ASP.NET Core developers now have full Razor editor support. We’ve also introduced JavaScript and TypeScript support.
- For iOS developers, we added WiFi debugging support for iOS and tvOS applications. We also improved the iOS provisioning system.
- Android developers will enjoy the new Android SDK manager built right into the IDE, as well as a device manager to keep track of all your devices and emulators
- Xamarin.Forms developers will enjoy an improved XAML editing experience
- Cloud developers have support for Azure Functions development using .NET Core.
- We support .NET Core 2.1 RC and C# 7.2.
- Code-styling rules can be configured per-project using .editorconfig files.
- A preview of Team Foundation Version Control support for Team Foundation Server and Visual Studio Team Services is now available.
We’re also shipping improvements to performance and stability, accessibility, and multi-language support, along with fixes for a number of bugs reported by our vibrant developer community. You can find the full list of changes in our release notes.
ASP.NET Core development with Razor, JavaScript, and TypeScript Editor Support
We partnered with the Roslyn and Visual Studio JavaScript tooling teams to reuse Razor, JavaScript, and TypeScript editor source code, bringing the editing experiences you know and love from Visual Studio 2017 to the Mac.
Official Razor support includes IntelliSense and syntax highlighting in .cshtml files
Our JavaScript editor has been rewritten to provide the core editor experience you expect, including IntelliSense, enhanced colorization, and brace completion. We’ve also added TypeScript editing support, which shares the same IntelliSense and colorization as our JavaScript experience.
Use .editorconfig files to Set Code Style Rules in Projects
Microsoft visual studio for mac shows red color javascript. One of my favorite features is finally here: .editorconfig
Visual Studio for Mac will now format your code following the conventions specified in the .editorconfig file. This will allow you to set your coding style, preferences, and warnings for your project; making it simpler for code that you contribute to other projects to follow the practices of those projects.
Xamarin.Forms Development
We now ship Xamarin.Forms templates that take advantage of .NET Standard Libraries.
Working with XAML just got better, too, with IntelliSense improvements providing better support for self-closing elements and more completions.
Android Development with Xamarin
On the Android side of the house, we added an integrated Android Device Manager dialog, eliminating the need to rely upon 3rd-party tools for device and emulator management. You can find this under Tools > Device Manager.
iOS Development with Xamarin
iOS fans will enjoy a streamlined Entitlements editor experience, making it a breeze to add capabilities and services to your iOS apps.
Simply open the Entitlements.plist file and jump right in! Not only that, our new Automatic Signing experience makes deploying your application to devices very simple. In the Signing section of the Info.plist editor, you’ll find using Automatic Signing makes the burdens of manually tracking your entitlements and provisioning devices things of the past.
Building Serverless solutions with Azure Functions
Our new Azure Functions templates now support the Azure Functions .NET Core SDK, empowering you to build, debug, and test Azure Functions locally. In addition, item templates provide guidance for building functions using the most common triggers, enabling you to get up and running with new functions in minutes.
After creating a new Azure Functions project, right-click and select Add > Add Function, then choose your favorite function from the template dialog.Check out our documentation for a walkthrough to create your first Function in Azure.
.NET Core 2.1 RC and C# 7.2
Visual Studio for Mac version 7.5 now supports .NET Core 2.1 RC. Major improvements include faster build performance, better compatibility with .NET Framework, and closing gaps in both ASP.NET Core and EF Core. You can read more about the .NET Core 2.1 RC release in the announcement blog post. Support for the newest C# release, version 7.2, is also available today.
Working with your source with Team Foundation Version Control
X Code
One of our most popular feature requests has been to add support for Team Foundation Version Control (TFVC) to access source saved in Team Foundation Server or Visual Studio Team Services. We heard you loud and clear! Today, we’re previewing a new extension to do just that.
To install the extension, navigate to Visual Studio > Extensions… in the Visual Studio for Mac menu and search the gallery for “team foundation”. We support Get, Commit (with associated work items), version history, and more.
Feedback
We hope you’ll find Visual Studio for Mac version 7.5 as delightful as we do. Let us know what you think! Your feedback helps us improve our products and better understand your needs as a developer.
Please let us know about issues via Help > Report a Problem. You’ll be able to track your issues and receive updates in the Visual Studio Developer Community.
Installation Project In Visual Studio
You can also provide product suggestions via the Help > Provide a Suggestion menu and vote on suggestions at the Visual Studio for Mac UserVoice site.
Visual Studio For Mac Download
Miguel de Icaza
Xamarin Studio For Windows
Miguel de Icaza, Distinguished Engineer, Mobile Developer Tools @migueldeicaza Miguel is a Distinguished Engineer at Microsoft, focused on the mobile platform and creating delightful developer tools. With Nat Friedman, he co-founded both Xamarin in 2011 and Ximian in 1999. Before that, Miguel co-founded the GNOME project in 1997 and has directed the Mono project since its creation in 2001, including multiple Mono releases at Novell. Miguel has received the Free Software Foundation 1999 Free Software Award, the MIT Technology Review Innovator of the Year Award in 1999, and was named one of Time Magazine’s 100 innovators for the new century in September 2000. |