简体   繁体   English

您能否将资源发送到 .NET 5 中独立的单文件应用程序中的进程?

[英]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.一种解决方法可能是创建一个安装程序并将帮助文件安装在用户的计算机上,但这种方法会破坏单个文件部署的全部意义。

  1. Use Application.GetResourceStream() to get the contents of your embedded CHM as a binary stream.使用Application.GetResourceStream()以二进制流的形式获取嵌入式 CHM 的内容。
  2. Use 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"获取临时文件名,并将该文件作为二进制流打开。
  3. Write the contents from (1) into (2), close (2).将(1)的内容写入(2),关闭(2)。
  4. Build and launch your process using the temporary file name from (2).使用 (2) 中的临时文件名构建并启动您的进程。
  5. Optionally, delete (2) when your application exits.或者,在您的应用程序退出时删除 (2)。

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

相关问题 .NET 6.0 控制台应用程序作为独立的单文件可执行文件 - .NET 6.0 Console app as a self-contained single file executable 我可以在自包含的进程中托管RavenDB吗? - Can I host RavenDB inside my self-contained process? 如何配置独立的单文件程序? - How to configure self-contained single-file program? 在 Windows 中发布便携式和独立的 .NET 应用程序 7 - Publish Portable and Self-Contained .NET Application in Windows 7 .NET 4.8 没有为 Linux 创建一个独立的文件 - .NET 4.8 not creating a self-contained file for Linux 发布用于Linux体系结构的.NET Core C#自包含应用程序 - Publishing .NET Core C# self-contained application for linux architecture 是否可以编译自包含的 ASP.NET Core Web 应用程序 - Is it possible to compile a self-contained ASP.NET Core Web Application 独立的 ASP.Net Core 不读取 appsettings.json 文件 - Self-Contained ASP.Net Core Not Reading appsettings.json file CefSharp.WPF 不会作为独立文件 .NET Core 运行 - CefSharp.WPF won't run as a self-contained file .NET Core “不支持”在不指定 RuntimeIdentifier 的情况下构建或发布自包含应用程序 - It is “not supported” to build or publish a self-contained application without specifying a RuntimeIdentifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM