简体   繁体   中英

Xamarin.Forms : “InitializeComponent” and “Package restore failed” Build Errors

After creating every single Cross Platform project in Visual Studio 2017 Preview 15.6.0 v1.1, I'm getting error from the picture, actually 2 errors.

The name 'InitializeComponent' does not exist in the current context

The second error is related to NuGet Package Manager, I can't update any of packages, error message:

Package restore failed. Rolling back package changes for 'testApplication.Android'.

描述中的错误

Failing some actual code error, i would try the following

In regards to

The name 'InitializeComponent' does not exist in the current context

Steps that worked for me

  1. Clean Solution
  2. Delete bins and objs directions in all projects
  3. Restart visual studio
  4. Rebuild


In regards to

Package restore failed

Try updating all packages for solution in the package package console

 Update-Package –reinstall 

In regards to your comments when trying Update-Package -reinstall

Update-Package : Package Xamarin.Android.Support.Design 26.1.0.1 is not compatible with monoandroid71 (MonoAndroid,Version=v7.1). Package Xamarin.Android.Support.Design 26.1.0.1 supports: monoandroid80 (MonoAndroid,Version=v8.0)

Also Check you are using the appropriate version of the Andriod Sdk

 Tools > Andriod > Andriod Sdk Manager 

One of two reason.

Your x:Class doesn't match up with the MainPage.xaml namespace. Male sure they match Or "Build Action" is not set to "Page" for MainPage.xaml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM