0

I am currently building a Xamarin Forms iOS app on top of .NET Standard v1.3. I am running into a problem with compilation of the app when I use Xamarin Studio on a Mac, but it works fine from Visual Studio on Windows, and on a separate machine running the new Visual Studio Preview for Mac.

In Xamarin Studio for Mac, I'm getting this error when compiling the app:

App.xaml.cs(25,13): error CS0103: The name `InitializeComponent' does not exist in the current context
Base/BaseView.xaml.cs(11,13): error CS0103: The name `InitializeComponent' does not exist in the current context
View/LoginView.xaml.cs(9,13): error CS0103: The name `InitializeComponent' does not exist in the current context

This happens on every XAML file in the solution. I can see why - the *.xaml.g.cs files are not being generated. On Visual Studio for Windows and Visual Studio Preview for Mac they are put into the project's obj/Release folder - but on Xamarin Studio for Mac, they aren't generated at all.

I have another Xamarin Forms app, which uses the full .NET Framework rather than .NET Standard. This app compiles fine on Xamarin Studio for Mac. This leads me to believe the problem may be .NET Standard-related.

On the main Mac I am running Xamarin Studio (6.1.5) with Mono 4.6.2, Xamarin.Android 7.0.2.42, Xamarin.iOS 10.3.1.8. On Windows I'm running Visual Studio 2015 Update 3 (14.0.25341) with Xamarin 4.2.2.11, Xamarin.Android 7.0.2.42, and Xamarin.iOS 10.3.1.8. On a second Mac I am running Visual Studio for Mac Preview 3 (7.0 build 1077) with Xamarin iOS 10.4.0.88.

I don't know if it helps at all, but in Visual Studio for Windows I also get this error in each XAML file (but the project still compiles fine):

Build action 'EmbeddedResource' is not supported by one or more of the project's targets.

Is there any reason why, on Xamarin Studio for Mac, the *.xaml.g.cs files would not be generated - perhaps related to using .NET Standard?

If I need to switch to Visual Studio Preview for Mac I'll consider it, but I'd rather not rely on a pre-release tool for a production project.

John
  • 5,452
  • 8
  • 37
  • 37
  • Xamarin does not support .net Core, may be you mean .net Standard? – Gusman Feb 17 '17 at 02:34
  • Apologies - I will correct the post. Yes, .NET Standard (1.3). – John Feb 17 '17 at 03:03
  • I think this is the issue: http://stackoverflow.com/questions/38857651/xamarin-studio-targeting-netstandard – Gusman Feb 17 '17 at 03:05
  • Thanks @Gusman - that post says that Xamarin Studio 6.0.2 onwards can consume .NET Standard libraries though, and I'm running Xamarin Studio 6.1.5. – John Feb 17 '17 at 03:09
  • Consume, but not create, if you have any project targeting .net standard on the solution then it will fail. The first version to support it is 6.2 and is in the beta channel. – Gusman Feb 17 '17 at 03:10
  • Ah, I see. OK, that makes sense. I'll try Xamarin Studio 6.2 on another test machine and check. Thanks! – John Feb 17 '17 at 03:11
  • How did you create the .NETStandard project? Just wondering if it uses a project.json file or is a .NET Core project. – Matt Ward Feb 19 '17 at 14:30
  • The project was created on a Windows machine with VS2015. It uses a project.json file yes. I'm currently trying Xamarin Studio 6.2 as this does look like it'll resolve the issue. – John Feb 20 '17 at 00:11
  • @Gusman - changing to Xamarin Studio 6.2 did indeed fix the issue. Thanks! Can you please submit this as an answer, and I'll mark it as correct? – John Feb 21 '17 at 03:03

1 Answers1

1

If you have any .net Standard project included on your solution you must use Xamarin Studio version 6.2 or higher or it will fail, previous versions only allow to consume .net Standard libraries, not to compile projects of this type.

Gusman
  • 14,905
  • 2
  • 34
  • 50
  • Thanks. In addition to using XS 6.2, I also found that the solution file I was compiling needed to not have a UWP project. With the UWP project included I was getting an "Object reference not set to an instance of an object" error when attempting to do a NuGet package restore. This, in turn, meant that the Xamarin Forms targets weren't properly installed - which meant that the *.xaml.g.cs files weren't generated. Completely removing the UWP project from the solution resolved this. A workaround was also to do two NuGet restores, since the first one failed but the second one succeeded. – John Feb 22 '17 at 20:42