Reputation: 4902
Using Visual Studio Community for Mac 7.3.3 (build 7)
I make an iOS project. Then make a new .NET Standard 2.0 lib.
Using the built in NuGet support I add Xamarin.Forms
to each Project.
In the Net Standard 2.0 Lib I Add -> New File
and Select Forms ContentPage Xaml
This creates an empty class and corresponding XAML file. In the classes constructor it contains 1 line:
InitializeComponent();
When I attempt to compile either the NET Standard 2.0 lib OR the iOS project, the compilation fails with the following error:
Error CS0103: The name 'InitializeComponent' does not exist in the current context (CS0103)
I have added no other code or dependencies to either project. Clearly I have missed something that is not obvious to me.
Upvotes: 3
Views: 14937
Reputation: 21
I think that you have moved your code to different folder. You can delete folder .vs in your project (this folder is hide) and reopen your project.
Upvotes: 0
Reputation: 11105
As DeveloperX said in the comments, open the property window on your XAML file and make sure Build Action = Embedded Resource
and the make sure Custom Tool = MSBuild:UpdateDesignTimeXaml
.
Finally, to fix a .NET Standard bug in VS add the following to your .NET Standard .csproj file
<ItemGroup>
<!-- https://bugzilla.xamarin.com/show_bug.cgi?id=55591 -->
<None Remove="**\*.xaml" />
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
</ItemGroup>
If you are still having problems, then it may be an issue with how the .NET Standard project was setup. Check out the following article which talks about converting a PCL to .NET Standard, which is what we did.
Upvotes: 7