简体   繁体   English

在 Visualstudio 中构建可执行文件时隐藏包含 GOOGLE_APPLICATION_CREDENTIALS 的 Json 文件

[英]Hide Json file containing GOOGLE_APPLICATION_CREDENTIALS when building executable file in Visualstudio

currently I am developing a tool that interacts with a Firebase Firestore database.目前我正在开发一个与 Firebase Firestore 数据库交互的工具。 When I want to make the C# Forms Application an executable file I get the.exe but also the json file which contains the Google App Credentials.当我想让 C# Forms 应用程序成为可执行文件时,我得到了 .exe 以及包含 Google App Credentials 的 json 文件。 However, I want to forward the tool so that you can't see the json file or read the contents of the file, so you only need the.exe file.不过我想转发一下这个工具,让你看不到json文件,也看不到文件内容,所以只需要.exe文件即可。 Is there a way to achieve this?有没有办法做到这一点? For example, define the app credentials in a C# script so that it compiles to the.exe file?例如,在 C# 脚本中定义应用凭据,以便它编译为 .exe 文件? If so how?如果是这样怎么办?

My current implementation looks like this:我当前的实现如下所示:

string path = AppDomain.CurrentDomain.BaseDirectory + @"cloudfire.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);

The cloudfire.json file is directly contained in the namespace "LUX". cloudfire.json 文件直接包含在命名空间“LUX”中。

I also tried making the cloudfire.json file a resource, since i read this post but then the problem is, that i can't set the path of the.json, if i try it like that:我还尝试将 cloudfire.json 文件作为资源,因为我阅读了这篇文章,但问题是,如果我这样尝试,我无法设置 .json 的路径:

var assembly = Assembly.GetExecutingAssembly();
            string resourceName = assembly.GetManifestResourceNames()
  .Single(str => str.EndsWith("cloudfire.json"));

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", resourceName);

I get the error: System.InvalidOperationException: "Sequence contains no matching element"我收到错误:System.InvalidOperationException:“序列不包含匹配元素”

Is there maybe a way to set the "GOOGLE_APPLICATION_CREDENTIALS" to the embedded cloudfire.json ressource file?有没有办法将“GOOGLE_APPLICATION_CREDENTIALS”设置为嵌入式 cloudfire.json 资源文件?

Add you file as embedded resource with name.将您的文件添加为带有名称的嵌入式资源。 And try to read by following code:并尝试通过以下代码阅读:

var resources = new ResourceManager("<namespace>", Assembly.GetExecutingAssembly());
var obj = resources.GetObject(<embedded_resource_key>); 
or 
var str = resources.GetString(<embedded_resource_key>)

暂无
暂无

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

相关问题 如何使用 c# 和使用 JSON 密钥但不使用 GOOGLE_APPLICATION_CREDENTIALS 从 Firebase 获取数据 - How to get data from Firebase using c# and using JSON key but not using GOOGLE_APPLICATION_CREDENTIALS 将 service.json 路径设置为 GOOGLE_APPLICATION_CREDENTIALS 环境变量 - Setting service.json path to the GOOGLE_APPLICATION_CREDENTIALS environment variable Firestore:如何设置 GOOGLE_APPLICATION_CREDENTIALS? - Firestore: how to set up GOOGLE_APPLICATION_CREDENTIALS? 如何在 C# 中从 Google Cloud Vision 设置 GOOGLE_APPLICATION_CREDENTIALS? - How to set the GOOGLE_APPLICATION_CREDENTIALS from Google Cloud Vision in C#? 在 Visual Studio 中构建 C# 应用程序时,如何在可执行文件名中嵌入版本信息? - How to embed the version information in the executable file name when building C# application in Visual Studio? C# 项目无法为 google vision 找到 GOOGLE_APPLICATION_CREDENTIALS - C# project unable to find GOOGLE_APPLICATION_CREDENTIALS for google vision C#.net MVC,设置Google Application Credentials JSON文件的路径 - C# .net MVC, set path to Google Application Credentials JSON file json 文件中的凭据未发布 - credentials in a json file not publishing 从另一个应用程序启动可执行文件时找不到文件 - File not found when executable launched from another application 在我的计算机上使用 Google Drive API 的 ~/.credentials/drive-dotnet-quickstart.json 文件在哪里? - Where is the ~/.credentials/drive-dotnet-quickstart.json file from using the Google Drive API on my computer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM