使用Xamarin Forms在Visual Studio中创建Hello World失败

6
我参考了这个解决方案 / 问题The type or namespace name 'Xamarin' missing in xamarin studio,但是从新的通用应用项目向导中构建应用程序仍然不可能。
Severity    Code    Description Project File    Line    Suppression State
Error   CS0117  'Resource.Attribute' does not contain a definition for 'actionBarSize'  
Project.Droid   C:\dev\Project.Droid\Resources\Resource.Designer.cs 29  Active

新手使用Xamarin有什么想法吗?

你正在使用哪个版本的Xamarin.Forms?其次,引用了哪些相应的Google支持库的版本? - Jon Douglas
目前已安装2.1.0.6529版本,是通过NuGet添加的。我不确定是否已安装Google支持库。 - Israel Lopez
你能把你的 Resource.desginer.cs 文件内容粘贴过来吗?可以用 gist 方式分享吗? - Jon Douglas
我们需要找到一行类似于以下代码的内容:public const int actionBarSize = 2130772085; 如果您在 Resource.designer.cs 文件中没有这样的元素,请尝试通过 NuGet 重新安装 Xamarin.Forms 并删除 Resource.designer.cs 文件。然后再次编译,该文件将被隐藏,将其重新添加到您的解决方案中。 - Jon Douglas
似乎不存在。你能否请尝试上述步骤?另外,在此期间,请将你的 bin/obj 文件夹清空。 - Jon Douglas
显示剩余3条评论
1个回答

4

好的,这是答案!我在本地重现了这个问题,看起来.csproj文件中缺少一些引用:

请确保将以下内容添加到您的.csproj文件引用部分中:

<Reference Include="Xamarin.Android.Support.Design, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\packages\Xamarin.Android.Support.Design.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.Design.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\packages\Xamarin.Android.Support.v4.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.AppCompat, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\packages\Xamarin.Android.Support.v7.AppCompat.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.CardView, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\packages\Xamarin.Android.Support.v7.CardView.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v7.CardView.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.MediaRouter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\packages\Xamarin.Android.Support.v7.MediaRouter.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v7.MediaRouter.dll</HintPath>
  <Private>True</Private>
</Reference>

您可以先从项目中删除Resource.designer.cs文件,重新构建您的项目,然后再将Resource.designer.cs文件添加回项目中。它应该会生成以下Attribute项:https://gist.github.com/JonDouglas/7adf61469ce21663d7f536a4aa27c7df

删除 Resource.designer.cs 文件可以让项目(.droid)编译通过。重新添加它会导致错误再次出现。我需要这个文件吗?如何重新添加它而不出现错误? - Gulzar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接