【问题标题】:Can't set Build Action to GoogleServiceJson无法将构建操作设置为 GoogleServiceJson
【发布时间】:2017-07-29 09:36:54
【问题描述】:

我正在使用 Xamarin-Android 制作应用程序,因此我需要将 Build Action 设置为我的 google-services.json 文件,但没有 GoogleServicesJson 这样的属性,当我尝试编写它时,它向我展示了一个例外:

“System.Runtime.InteropServices.ExternalException”类型的异常 被扔了。

我尝试保存并重新启动 Visual Studio,但没有解决问题。

如果你知道如何解决这个问题,请帮助我! :)
That's the file I'm clicking on

【问题讨论】:

  • 我在整个解决方案中添加了屏幕截图,因此您可以看到我正在单击 Xamarin.Android 项目中的文件。 :)
  • @SushiHangover 是的,但是尝试在VS 2015中这样做,没有区别
  • @SushiHangover 我加了 Xamarin.Firebase.Messaging,以为就够了。但是现在当我添加 Xamarin.GooglePlayServices.Basement 时可以设置它,非常感谢! :D
  • 尝试右键单击文件/属性/构建actoin/googleservicesjson - 为我修复它。

标签: xamarin push-notification xamarin.android google-play-services


【解决方案1】:

GoogleServicesJson 构建类型来自 Xamarin.GooglePlayServices.Basement.targets

如果您的项目没有通过其依赖项之一安装Xamarin.GooglePlayServices.Basement,通常是Xamarin.GooglePlayServices.GcmXamarin.Firebase.Messaging,如果我们正在谈论消息传递,那么您将无法使用该构建操作。

添加安装 Basement 的包后,或手动添加后,您的 .csproj 将包含 Xamarin.GooglePlayServices.Basement.targets 的导入,GoogleServicesJson 将作为构建类型提供:

.csproj 导入示例:

  <Import Project="..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets" Condition="Exists('..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets')" />

【讨论】:

  • 谢谢@SushiHangover。对于发现此问题的任何人,请记住更新 Xamarin.GooglePlayServices.Basement 的版本以及可以在导入指令中找到它的相对路径。此外,如果您的解决方案中有多个 Android 项目,则路径可能指向不同的项目,而不是您当前的项目,因此您可能需要使用 FileExplorer 进行一些挖掘。
  • 如果安装后看不到,重启Visual Studio即可。
  • 值得注意的是,我引用了另一个 VStudio 项目,该项目对 Xamarin.Firebase.Messaging 具有此 NuGet 依赖项,但应用程序项目没有。它依赖于参考项目 NuGets 编译良好,但 Visual Studio 没有为 IDE 构建操作选择它 - 更多信息在这里 对我来说,我添加了一个 firebase NuGet 以确保出现构建选项 - 按照forums.xamarin.com/discussion/175159/…?
  • 我需要使用的任何特定版本.. 我已经安装了 71.1620.4 但我找不到 GoogleServiceJson 作为构建选项
【解决方案2】:

即使在安装“Xamarin.GooglePlayServices.Basement”之后 GoogleServiceJson 选项也没有显示。令人惊讶的是,但是当我退出 Xamarin 工作室并再次打开它时,它开始显示。

【讨论】:

  • Visual Studio for mac 相同
  • 我不必关闭 IDE (Visual Studio for Mac),我只需要关闭并重新打开解决方案。
  • 我也一样!谢谢
  • 今天我在使用 VSMac 时遇到了同样的问题。我也确定在阅读您的答案后我已经重新启动过一次我再次尝试并且它有效,所以谢谢。
【解决方案3】:

1-首先下载这些包:

Xamarin.Firebase.Common

Xamarin.Firebase.Config

Xamarin.Firebase.Iid

Xamarin.GooglePlayServices.Base

Xamarin.GooglePlayServices.Basement

Xamarin.GooglePlayServices.Tasks

2-然后重新启动并重建 3-来自 google-services.json --> 属性 --> 构建操作:GoogleServicesJson

【讨论】:

  • 我需要使用的任何特定版本.. 我已经安装了所有软件包,但我无法找到 GoogleServiceJson 作为构建选项..
【解决方案4】:

在 Visual Studio 中关闭项目并重新打开它。这对我有用:)

【讨论】:

    【解决方案5】:

    首先下载这些包:

    然后重启

    【讨论】:

    • 请将包名添加到您的答案文本中。另外,请将“在此处输入图片描述”更改为有用的描述。
    【解决方案6】:

    GoogleServiceJsom 来自 Xamarin.GooglePlayServices.Basement 包。如果安装包后不可见,重新启动你的 Visual Studio 项目,它将工作

    【讨论】:

      【解决方案7】:

      我认为我做错了,但是您没有像 Mac 中的示例一样通过右键单击它来获得构建操作

      PS 你没有右键点击 Google-Services.json 并查看 Build avtion 您按属性,然后在属性中找到 Build 操作

      【讨论】:

        【解决方案8】:

        在使用 AppCenter 时,我没有将 App Center 和 App Center Push 包添加到 Android Dependencies 文件夹。添加 GoogleServicesJson 后立即出现

        【讨论】:

          【解决方案9】:

          我对此感到困惑,因为 Microsoft 指南 https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows 说要直接安装 Xamarin.GooglePlayServices.Base。

          什么有效: 通过 Nuget 安装 Xamarin.GooglePlayServices.Gcm

          【讨论】:

            【解决方案10】:

            我尝试安装人们建议安装的每个软件包,在每个软件包之后我都重新启动了我的 Visual Studio,尝试以管理员身份运行,重新启动我的计算机,但没有任何效果。我无法让 GoogleServicesJson 选项显示在我的构建操作列表中。

            查看@SushiHangover 的评论,我尝试将该行复制并粘贴到我的 .shproj 文件中,并将其更改为与我的 nuget 包的路径匹配

              <Import Project="C:\Users\<my user>\.nuget\packages\xamarin.googleplayservices.basement\117.6.0.3\build\monoandroid90\Xamarin.GooglePlayServices.Basement.targets" Condition="Exists('C:\Users\<my user>\.nuget\packages\xamarin.googleplayservices.basement\117.6.0.3\build\monoandroid90\Xamarin.GooglePlayServices.Basement.targets')" />
            

            这是唯一最终对我有用的东西。希望它可以帮助别人!

            【讨论】:

              猜你喜欢
              • 2018-04-14
              • 1970-01-01
              • 1970-01-01
              • 2012-07-20
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-12-25
              • 2017-06-21
              相关资源
              最近更新 更多