在.exe文件中嵌入JSON文件
我试图将我的控制台应用程序发布到1个EXE文件中。我通过将DLL文件嵌入到EXE文件中,通过添加到CSPROJ文件中:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
但是,我仍然需要我的文件extractConfig.json在与EXE文件同一空间中,否则它将无法运行。如何也将此文件嵌入EXE?
它目前正在像这样发表:
I am trying to publish my console application into 1 exe file. I have managed to embed the dll files into the exe file by adding to the csproj file:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
However I still need my file extractConfig.json in the same space as the exe file as well or else it will not run. How can I embed this file into the exe as well?
It is currently getting published like so:
But I need it so it is just the exe file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几个选项:
不存在,请创建配置
如果程序启动时 ,请检查配置文件是否存在。如果没有,您可以创建它。您可以从序列化的默认配置对象中创建此文件,也可以将配置文件作为字符串资源或其他方式包含。我还将考虑将此文件放在LocalAppData文件夹中,因为您可能没有对.exe文件的文件夹的写入访问权限。
从包装中排除配置文件,
您可以为配置文件添加dubludeFromsingLefile选项,以使其不包含在单个.exe文件中。这显然需要您部署多个文件。
There are a few options:
Create the config if it does not exist
When the program starts you check if the config file exist. If not, you create it. You could create this file from a default configuration object that you serialize, or include the configuration file as a string resource or some other way. I would also consider placing this file in the localappdata folder instead, since you might not have write access to the folder of the .exe file.
Exclude the configuration file from the package
You can add the ExcludeFromSingleFile option for the config file so that it is not included in the single .exe file. This will obviously require you to deploy multiple files.
与我正在与之合作的人进行了交谈,并与@sironeofmany的建议有关,现在我正在使用常数而不是JSON文件,而JSON文件很容易使我只使用1 EXE文件。
感谢大家的建议
Spoke with the people I am working with and have gone with the suggestion from @SirOneOfMany and I am now using constants rather than the json file which easily allows me to just have the 1 exe file.
Thanks everyone for the suggestions