简体   繁体   English

Xamarin.Forms:“ InitializeComponent”和“包还原失败”生成错误

[英]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. 在Visual Studio 2017预览版15.6.0 v1.1中创建每个跨平台项目后,我从图片中得到了错误,实际上是2个错误。

The name 'InitializeComponent' does not exist in the current context 名称“ InitializeComponent”在当前上下文中不存在

The second error is related to NuGet Package Manager, I can't update any of packages, error message: 第二个错误与NuGet软件包管理器有关,我无法更新任何软件包,错误消息:

Package restore failed. 程序包还原失败。 Rolling back package changes for 'testApplication.Android'. 回滚“ 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 名称“ InitializeComponent”在当前上下文中不存在

Steps that worked for me 对我有用的步骤

  1. Clean Solution 清洁溶液
  2. Delete bins and objs directions in all projects 删除所有项目中的垃圾箱和objs方向
  3. Restart visual studio 重新启动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 -reinstall时的评论

Update-Package : Package Xamarin.Android.Support.Design 26.1.0.1 is not compatible with monoandroid71 (MonoAndroid,Version=v7.1). Update-Package:软件包Xamarin.Android.Support.Design 26.1.0.1与monoandroid71不兼容(MonoAndroid,Version = v7.1)。 Package Xamarin.Android.Support.Design 26.1.0.1 supports: monoandroid80 (MonoAndroid,Version=v8.0) 软件包Xamarin.Android.Support.Design 26.1.0.1支持:monoandroid80(MonoAndroid,Version = v8.0)

Also Check you are using the appropriate version of the Andriod Sdk 还要检查您是否使用了适当版本的Andriod SDK

 Tools > Andriod > Andriod Sdk Manager 

One of two reason. 两个原因之一。

Your x:Class doesn't match up with the MainPage.xaml namespace. 您的x:ClassMainPage.xaml命名空间不匹配。 Male sure they match Or "Build Action" is not set to "Page" for MainPage.xaml 确认他们匹配的男性,或者MainPage.xaml “构建动作”未设置为“页面”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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