[英]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.