[英]Can you send resources to a process in a self-contained, single file application in .NET 5?
I'm trying to include a .CHM (Microsoft Compiled HTML help) documentation file in my WPF application.我正在尝试在我的 WPF 应用程序中包含一个 .CHM(Microsoft Compiled HTML 帮助)文档文件。 It is set as a Resource in my application.
它在我的应用程序中设置为资源。
I use .NET 5 and I want to create a self-contained application using single file deployment.我使用 .NET 5,我想使用单个文件部署创建一个独立的应用程序。 When I have a .CHM-file on my local machine, I can execute the file to open a default help viewer in Windows.
当我的本地机器上有 .CHM 文件时,我可以执行该文件以在 Windows 中打开默认帮助查看器。
var p = new Process();
p.StartInfo = new ProcessStartInfo(@"D:\helpfile.chm")
{
UseShellExecute = true
};
p.Start();
I want to do something similar with the resource I am including in my project.我想对我在项目中包含的资源做类似的事情。 However, in a single file deployment there is no such thing as file paths (see https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file ).
但是,在单个文件部署中,没有文件路径之类的东西(请参阅https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file )。 As I want to step "out of" the application and send the file to the process, can I send the whole file to a process out of my application?
当我想“退出”应用程序并将文件发送到进程时,我可以将整个文件发送到我的应用程序之外的进程吗?
A workaround might be to create an installer and have the help-file be installed on the user's computer, but that kind of defeats the whole point of having single file deployment.一种解决方法可能是创建一个安装程序并将帮助文件安装在用户的计算机上,但这种方法会破坏单个文件部署的全部意义。
Application.GetResourceStream()
to get the contents of your embedded CHM as a binary stream.Application.GetResourceStream()
以二进制流的形式获取嵌入式 CHM 的内容。System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".chm"
to get a temporary file name, and open that file as a binary stream.System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".chm"
获取临时文件名,并将该文件作为二进制流打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.