【发布时间】:2021-09-23 04:05:41
【问题描述】:
当我尝试在我的 Xamarin 项目中运行此函数时,我收到错误 System.IO.FileNotFoundException: 'Could not find file "/private_key.json"'。该文件在主项目中,所以我不确定我做错了什么。我还将“复制到输出目录”切换为“始终复制”
public async void test()
{
FirebaseApp.Create(new AppOptions()
{ Credential = GoogleCredential.FromFile("private_key.json") });
// This registration token comes from the client FCM SDKs.
var registrationToken = App.notiToken;
// See documentation on defining a message payload.
var message = new Message()
{
Token = registrationToken,
Notification = new Notification()
{
Title = "Test from code",
Body = "Here is your test!"
}
};
// Send a message to the device corresponding to the provided
// registration token.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(false);
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
}
【问题讨论】:
-
文件的构建操作是什么?
-
我已将其设置为无
-
应该是“内容”
-
仍然出现同样的错误
-
尝试使用绝对路径。
标签: c# firebase visual-studio xamarin.forms