2020. 2. 7. 21:53ㆍ카테고리 없음
Since I’ve recently started using Xamarin for cross platform development, I thought it would be nice to share with the community how I’ve got past some of the issues which tripped me up for a while when I was becoming familiar with it. This isn’t really a normal “getting started with Xamarin” tutorial – there’s lots of them already out there already, – but hopefully anyone starting off with Xamarin will find it useful. I use Windows 10 (and have installed the Creator’s Update) – this allows me to use. You’ll know if you’re on the Creator’s Update version if your Windows build number is 1703. If you’re on a different version of Windows, you might have different experiences to me (you can check your version by going to Windows Settings - System - About). Before we begin – what’s Xamarin and why should I use it? With tools built into Visual Studio, developers can create native applications in C# for Windows, Mac and Linux devices.
Download Visual Studio Code for macOS. Double-click on the downloaded archive to expand the contents. Drag Visual Studio Code.app to the Applications folder, making it available in the Launchpad.
So instead of writing and managing three different codebases for three different platforms, developers can just write their code once and deploy it to different app-stores. Installing Xamarin tools for Visual Studio 2017 With Visual Studio 2017, it’s very easy just open up the setup wizard, select the Xamarin tools (as shown below) and just wait for it to install. It’s probably going to take a long time to install VS2017 with Xamarin – adding Xamarin to the base Visual Studio install makes it about 25GB bigger. Tip: If you leave your machine to download and install Xamarin, it’s worth adjusting your power settings to make sure an unattended machine doesn’t switch off in the middle of the download – like mine did the first time ( facepalm). Creating a project with the default Xamarin template This bit is straightforward to anyone who’s created a new project in Visual Studio 2017 before. Select File - New Project to open the dialog below, and choose a name for the project: After clicking OK on the dialog above (which chooses a Cross Platform App project type), the dialog will close and open a new project. I chose to use Xamarin.Forms (which allows developers to create ).
I also chose to create a because I only expect my code to be used in my application, rather than shared with other developers as a (you can read more about the differences between Shared Projects and Portable Class Libraries ). When you click OK, the project and files will be created, and a window like the one below will appear with instructions for setting up the Mac Agent. (I don’t have a Mac and I’d need Visual Studio Enterprise to use this anyway, so I normally click on the “Don’t show this again” box in the bottom left corner). Finally you’ll be prompted for the versions of Windows that you want the UWP flavour of your project to target. I normally just click OK here. At this point, you’ll have a simple Xamarin solution in Visual Studio 2017, which contains 4 projects – one for iOS, one for Android, one for UWP, and one shared project. Also notice that there is one file open in VS2017 after you create the solution – App.xaml.cs in the shared project.
I’ll explain why this is relevant later. And now for the gremlins ex machina After this point, I hit a few snags.
Visual Studio On A Mac
Things I wanted to do that didn’t work out of the box for me were:. Compile the application without error or warnings.
Run the application in a Windows Phone Emulator. Run the application in an Android Emulator I’ll run through some of the symptoms of problems I encountered trying the things above, and how I fixed them. Compiling the solution led to multiple warnings and errors Tip: Prepare to wait a while when building the solution for the first time – it needs to download a lot of NuGet packages.
Unfortunately my attempt to compile the project out of the box showed an error in the UWP project and a bunch of warning messages for the Android project. Getting rid of the error CS0103 – ‘InitializeComponent’ does not exist in the current context The error reports “ The name ‘InitializeComponent’ does not exist in the current context.” I eventually noticed a couple of things that seemed a bit bizarre:. Even though I have an error, the message in the status bar in the bottom left reports “Rebuild All succeeded” – both can’t be right surely?. This error relates to the App.xaml.cs file which is open in the editor panel. When I opened Main.xaml.cs from the Shared Project in the VS2017 editor, I now see two errors (as shown in the image below). So these errors don’t seem to negatively affect the build, and if I really want to get rid of them, I can just close those files which gets rid of the errors (as shown below).
Getting rid of warnings about $(TargetFrameworkVersion) mismatches Three of the warnings I saw were very similar: The $(TargetFrameworkVersion) for Xamarin.Forms.Platform.dll (v7.1) is greater than the $(TargetFrameworkVersion) for your project (v6.0). You need to increase the $(TargetFrameworkVersion) for your project. The $(TargetFrameworkVersion) for Xamarin.Forms.Platform.Android.dll (v7.1) is greater than the $(TargetFrameworkVersion) for your project (v6.0). You need to increase the $(TargetFrameworkVersion) for your project.
The $(TargetFrameworkVersion) for FormsViewGroup.dll (v7.1) is greater than the $(TargetFrameworkVersion) for your project (v6.0). You need to increase the $(TargetFrameworkVersion) for your project. The warning says I need to increase the TargetFrameworkVersion for my Android project, but when I look at the properties for this project, I actually can’t increase it past version 6 (MarshMallow). Fortunately we’re not at a dead end here – we can go to the Start Menu, and search for the “SDK Manager” for Android, which is installed with the Xamarin component of Visual Studio 2017 (shown below). Tip: Run the Android SDK Manager as administrator by right-clicking on the shortcut and select “More - Run as administrator”.
If you don’t run as administrator, you might get an error later when the program tries to create a temporary folder for downloads. When I start the Android SDK Manager, it analyses the packages presently installed, and advises what needs to be updated. On my system, 10 packages needed to be installed or updated, as shown below.
When I click on the “Install 10 packages” button, another window appears asking me to accept the licence. I accepted the licence and clicked on “Install”.
The installation and update procedure starts – this can take a few minutes. Once it’s finished installing, let’s return to Visual Studio 2017 – I restarted it, and then cleaned and rebuilt the solution. This time the warnings about $(TargetFrameworkVersion) mismatches are gone. Getting rid of warning IDE0006 – “Error encountered while loading the project” I sometimes found that I had a warning IDE0006 which advised “ Error encountered while loading the project. Some project features, such as full solution analysis for the failed project and projects that depend on it, have been disabled“. This usually happened just after I created a project, and I found that if I close VS2017, restart it, and re-open and rebuild the solution the warning disappears. So to summarise, in order to compile the default project without errors or warnings:.
Run the Android SDK manager as administrator, and install/update the recommended packages. Restart Visual Studio 2017 and re-open the project. Close all files from the shared project which have the type.xaml.cs. Running in your application in the Windows Phone Emulator Tip: If you want to run your application in an emulator, you’ll definitely need a 64-bit machine which allows hardware virtualisation. Your machine will also need to be pretty powerful, or you might find running an emulator to be unbearably slow. I found this to be straightforward as soon as I installed a Windows Phone emulator. If you don’t have any Windows Phone emulators installed, you can grab some from here: I changed the start-up project to the UWP project, and changed the debugging target to be one of the Windows Phone Mobile emulators.
After hitting play (or F5) to start running the Windows UWP application in a Windows Phone emulator, I was prompted to set my machine into Developer mode to allow me to load apps – I just had to select the third option (“Developer mode”) as shown in the image below (you can access this screen from Start - Settings - For developers). But after changing this setting, everything worked well – no gremlins here. The phone emulator starts up after a couple of minutes, and I was easily able to see the Xamarin application in the list of apps installed to the phone emulator. And when I run the Xamarin app in the emulator, I see the correct result – a simple form with a message saying “Welcome to Xamarin Forms!” Running your application in the Android Emulator Visual Studio 2017 comes packaged with several Android Emulators – you can see them if you change the target project to the Android one, and look at the dropdown list on its right. Tip: I never use either the two emulators which target ARM. I have never managed to successfully deploy a project to one of these emulators, even with a reasonably powerful machine.
If you don’t believe me, Visual Studio even gives you a warning if you try to use them: It’s much, much faster to target one of the emulators which targets x86. Use the Android x86 emulator – but you need to turn Hyper-V off You don’t need to uninstall Hyper-V to run the Android x86 emulator on Windows 10 – you just need to turn it off. The command to do this is very simple from a command prompt running as administrator: /set hypervisorlaunchtype off Reboot for this setting change to take effect.
Of course it might not suit you to turn Hyper-V off on your machine – and another alternative is to deploy to an actual Android device – there’s some great instructions for this here: My experience was that I couldn’t successfully start and deploy my project to an Android emulator from Visual Studio 2017. However, I was able to start the Android emulator from the Android AVD Manager, available from the start menu (as shown below). When you start this program, you’ll see a dialog like the one below which lists the Android Virtual Devices available on your development machine. Select one of the x86 emulators, and click on the “Start” button. Accept the default options on the launch screen, and an Android phone emulator will start. Now go back to Visual Studio 2017.
Select the emulator which you’ve just started in the drop down list on the right of the green “Play” arror. Now right click on the Android project, and select “Deploy Solution”. This should now deploy the Xamarin application to the Android emulator, as shown below (our app is in the top row, second column): And when we click on the Xamarin application icon in the emulator, as expected we see the same screen as in the Windows Phone emulator which says “Welcome to Xamarin Forms!” Wrapping up This was just a quick post to help other Xamarin developers who are starting out avoid some of the headaches I had. And just to be really clear, I’m not criticising Xamarin or Visual Studio – getting code to work on 3 different platforms which are constantly changing and updating is pretty miraculous, and ultimately the things I had to do weren’t that big a deal to change. There are already a few troubleshooting guides from Microsoft on Xamarin The tips below are things I didn’t find covered anywhere else. Sometimes errors (for example, CS0103) are mis-reported by VS2017 for files which are open in the editor, particularly.xaml.cs files from the Shared Project – try closing these files and rebuilding to see if the errors go away. Other warnings appear after the project is first created (for example, IDE0006), but if you restart VS2017 and re-build the project, the warning disappears.
Opening the Android SDK Manager as administrator and updating the libraries you have on your development machine can help to remove warnings related to TargetFrameworkVersion mismatches – remember to restart VS2017 after the update, and then clean and rebuild your solution through VS2017. Don’t use the Android ARM emulators on Windows 10 – instead start an x86 emulator from the Android AVD manager, and deploy from VS2017 to the emulator which is running.
If the x86 emulator won’t start, you might need to disable Hyper-V using the command “ bcdedit /set hypervisorlaunchtype off“. About me: I regularly post about.NET – if you’re interested, please, or have a look at my previous posts.
Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode. Please join us on and in the and organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links. Our sincere thanks to everyone who has contributed on this bug tracker over the years.
Thanks also for your understanding as we make these adjustments and improvements for the future. Please create a new report on or with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report. Brendan Zagaeski (Xamarin Team, assistant) 2017-04-11 03:33:44 UTC Xamarin versions installed by latest Visual Studio for Mac Preview are incompatible with the default Stable Xamarin version installed by Visual Studio on Windows This is a bug to track the on-going compatibility story between the default Xamarin versions installed by Visual Studio for Mac Preview and the default Stable Xamarin versions installed by Visual Studio 2017 and Visual Studio 2015 on Windows.
At the time of filing, the Xamarin.iOS Alpha version installed by Visual Studio for Mac Preview 6 is not compatible with the current Stable XamarinVS 4.4.0.34 (part of the Xamarin 15.1 release 1) on Windows. The most visible current symptom of this problem is the error 'The root assembly. Conflicts with another assembly' when building Xamarin.iOS projects. ## Recommended resolution in production environments: downgrade to the Xamarin Stable channel on the Mac using Xamarin Studio 1.
Open 'Xamarin Studio' on the Mac. Navigate to 'Xamarin Studio Check for Updates'. Select 'Update channel Stable' in the dialog. Click the 'Switch channel' button. Proceed to download and install the Stable products. Note: Visual Studio for Mac Preview 6 will not be able to run in this configuration because it requires the Mono 5.0 Alpha version. ### 'Experimental' option to re-enable VS for Mac Preview 6 After downgrading, install just the Mono 5.0 Alpha version (as listed on ) alongside the Stable versions of the other products: ## Alternate 'experimental' resolution: downgrade just Xamarin.iOS to the current Stable version on the Mac 1.
Run the latest VS for Mac Preview installer 1, or install all of the updates that are available on the Alpha channel in VS for Mac Preview. Install the following package on the Mac to downgrade just Xamarin.iOS to the current Stable channel version: (This package can also be found on the Xamarin account downloads page as described on 2.) 2 3.
Visual Studio for Mac Preview will continue to show the available update for Xamarin.iOS 10.10.0.0. Be sure not to run the 'Install Update' action in the updater dialog to avoid re-upgrading that package. Brendan Zagaeski (Xamarin Team, assistant) 2017-04-11 03:38:06 UTC ## Steps to demonstrate the current incompatibility 1. Install Xamarin through Visual Studio on a system that did not previously have Xamarin installed. Or ensure Xamarin is up-to-date on the latest Stable version in Visual Studio 2015.
Run Visual Studio On Mac
Or ensure that Visual Studio 2017 is updated to the latest available version 15.1 (26403.03) 1 via 'Tools Extensions and Updates'. Install Visual Studio for Mac Preview 6 (7.0.0.2715) either via the installer 2 or via 'Visual Studio Check for Updates' in an existing installation. Allow Visual Studio for Mac Preview 6 to install the latest updates from 'Visual Studio Check for Updates'. (As of VS for Mac Preview 6, this menu only includes the 'Alpha' channel, which currently contains the 15.2 Preview version of Xamarin.iOS: Xamarin.iOS 10.10.) 4. Create a new 'Visual C# iOS iPhone Single View App (iPhone)' project in Visual Studio on Windows. Attempt to build the project in the 'Debug iPhoneSimulator' configuration.
## Results The build fails as step 5 due to an incompatibility between Xamarin 15.1 Stable (XamarinVS 4.4.0.34) and the Xamarin.iOS 15.2 Alpha Preview (Xamarin.iOS 10.10.0): The root assembly /Users/macuser/Library/Caches/Xamarin/mtbs/builds/SingleViewIphone1/5c6e4fb0c5dfb9c08d5d52/bin/iPhoneSimulator/Debug/SingleViewIphone1.exe conflicts with another assembly (/Users/macuser/Library/Caches/Xamarin/mtbs/builds/SingleViewIphone1/5c6e4fb0c5dfb9c08d5d52/bin/iPhoneSimulator/Debug/SingleViewIphone1.exe). Brendan Zagaeski (Xamarin Team, assistant) 2017-04-11 03:47:12 UTC Comment hidden (obsolete) ## Alternate future resolution: upgrade to the upcoming 15.2 Alpha versions for Xamarin on Windows As mentioned in the Release Blog post for the 15.2 Alpha version 1, the 'initial Alpha release currently only includes updates for Mac and is not compatible with the existing Stable Xamarin version in Visual Studio on Windows.' 1 Once the corresponding Alpha versions for Windows have been published, updating to those will be another way to resolve the Xamarin.iOS version incompatibility, but those versions are not yet available.
I will update this bug once those versions have been published. Brendan Zagaeski (Xamarin Team, assistant) 2017-04-12 04:07:24 UTC ## Alternate resolution for VS 2015 and VS 2013 user: update to the 15.2 Alpha versions for Xamarin on Windows The new Xamarin.VisualStudio 4.5.0 Alpha version that has been published today 1 includes compatibility with the Xamarin.iOS 10.10.0 Alpha version on Mac. Of course, please note that both packages are Alpha versions and so might contain other issues that have not yet been resolved.
Free Visual Studio For Mac
Also, as mentioned in the corresponding Release Blog post 1: This Alpha release is not yet available in Visual Studio 2017. This post will be updated within the next day with the steps to try this release in Visual Studio 2017. If you use Xamarin.iOS in Visual Studio 2017, be sure to wait for those steps before installing these preview versions on the Mac. 1 I will update this bug again when the installation steps for Visual Studio 2017 have been published.
Brendan Zagaeski (Xamarin Team, assistant) 2017-05-04 20:22:51 UTC ## Update: Alternate resolution now also available for VS 2017 by installing a Visual Studio Preview instance As of the April 20 (26419.01 – Preview) version, Visual Studio 2017 Preview 1 now includes the Xamarin.VisualStudio extension version 4.5.0 that is compatible with the Xamarin.iOS 10.10.0 Mac version. Visual Studio 2017 Preview can be installed as a separate instance alongside the non-preview instance of Visual Studio 2017. That side-by-side Preview instance will be compatible with the default Xamarin.iOS 10.10.0 Alpha/Beta version that Visual Studio for Mac installs. Brendan Zagaeski (Xamarin Team, assistant) 2017-05-22 23:02:28 UTC ## Bookkeeping note: Update for the general availability of Visual Studio for Mac on May 10 Visual Studio for Mac now offers all 3 updater channels, so users can now follow the normal steps to keep the Xamarin versions on their Windows and Mac computers in sync. For any users still seeing the 'The root assembly. Conflicts with another assembly' error, first double-check that your Windows and Mac computers are in sync with one the channels from, and then be sure to clean the solution. If the 'The root assembly.
Conflicts with another assembly' error persists even when the Windows and Mac computers are on matching versions, please file a new bug report, being sure to include the complete version information from both computers, and being sure to mention whether the issue affects all projects (such as new template projects) or only certain existing projects.