如何使用 MSIX 允许可编辑的 .Net 生成配置文件? [英] How to allow for editable .Net generated config files with MSIX?

查看:29
本文介绍了如何使用 MSIX 允许可编辑的 .Net 生成配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试帮助将 .Net 服务移植到更现代的 .Net 版本(可能是 Core)并使用 MSIX 安装程序.该应用程序有几个由编译器生成的配置文件(在源代码中它们是 app.config,但编译后它们变成了 *.exe.xml),它们安装在二进制文件旁边的程序文件中,还有一个 GUI 助手应用程序和应用程序本身可以修改它们以改变服务行为(端口、IP、tls 证书等).

I am trying to help port a .Net service to a more modern .Net version (possibly Core) and use the MSIX installer. The application has several configuration files generated by the compiler (in source they are app.config but compiled they become *.exe.xml), they are installed into Program File right next to the binaries and a GUI helper app as well and the application itself can modify them to change service behavior (port, ip, tls cert, etc).

不允许在 C:\Program Files\WindowsApps\package_name 下写入.不允许在 C:\Program Files\WindowsApps\package_name 下写入.

Writes under C:\Program Files\WindowsApps\package_name are not allowed.Writes under C:\Program Files\WindowsApps\package_name are not allowed.

我面临的问题是 MSIX 安装程序使得它的程序文件沙盒版本中的文件无法写入 (见上文).这意味着无法配置此应用程序,因此我不仅要弄清楚如何使应用程序再次可配置,还要弄清楚 Windows 希望如何处理应用程序配置.

The problem I am facing is that the MSIX installer makes it so that files in it's sandboxed version of Program Files cannot be written to (see above). That means that this application cannot be configured, so I am trying to figure out not only how to make the app configurable again, but also how windows wants to handle app configuration.

现在似乎有两种通用方法可以做到这一点:

Right now it seems like there is two general approaches to do this:

  1. 将配置数据写入服务帐号的 AppData/local 文件夹
  2. 尝试在另一个文件夹中模仿 /etc/Myservice 行为.(意味着包含服务配置数据的本地系统范围目录)
  1. write the configuration data to the service account's AppData/local folder
  2. try to mimic a /etc/Myservice behavior in another folder. (meaning a local system-wide directory that houses configuration data for the service)

如果您建议 #1,请回答以下附加问题:

If you suggest #1 please answer the following additional questions:

  1. 如何将应用程序配置文件移动到用户配置文件目录
  2. 具有普通帐户的管理员如何使用上述 GUI 帮助程序修改服务帐户的 AppData 文件夹中的配置文件?(他们是否需要启用对服务帐户的桌面访问、登录和运行 GUI)?

如果您建议 #2:

  1. 您建议该目录存在于何处(特别是 MSIX 将允许它存在于何处)?
  2. 如何告诉 .Net 应用程序文件不在它旁边?我可以只使用 AppData.CurrentDomain.SetData 吗?

推荐答案

好吧,在系统帐户上运行的服务对所有用户都是一样的,所以我会说 CommonApplicationData 是一个更好的文件夹用于存储其设置,而不是 appdata.您的服务和任何需要部署自定义配置文件的管理员都可以轻松访问此文件夹.

Well, a service running on the system account is the same for all users, so I would say that CommonApplicationData is a better folder for storing its settings, instead of appdata. This folder is easily accessible to both your service and to any admin that needs to deploy a custom config file.

在 AppData 中,您应该只存储实际的用户文件(例如特定用户在您的应用内执行的操作生成的文件或设置 - 因此不同的用户使用不同的文件).

In AppData you should store only actual user files (like files or settings generated by the actions taken inside your app by a specific user - thus different files for different users).

现在,第二部分是您需要配置代码以从自定义路径加载配置文件,而不是在 EXE 旁边查找它.我不是 .NET 专家,但经过快速搜索后,我发现了这一点:

Now, the second part is where you need to configure you code to load the config file from a custom path instead of looking for it next to the EXE. I am no .NET expert but after a quick search I found this:

我不清楚您的客户如何使用 GUI 辅助工具来自定义配置文件.这是否只是 IT 部门人员用来生成配置文件的工具,然后他们会复制该文件并使用 MSI/MST 文件(或通过其他一些自定义部署方法)将其部署到最终用户计算机上)?

What is not clear to me is how your customers use the GUI helper tool to customize the config file. Is this just a tool that is used by someone from the IT department to generate the config file, and then they would copy that file and deploy it to the end-user machines using an MSI/MST file (or through some other custom deployment method)?

如果您的应用程序仅由 IT 人员部署,那么您可以尝试另一种更简单(而且非常优雅)的解决方案,为其提供自定义配置文件,这实际上不需要任何代码更改.

If your application is only deployed by IT folks, then you can try another simpler (and much elegant) solution for providing it with a custom config file, which actually doesn't require any code changes.

您仍然可以将配置文件留在程序文件中的 EXE 旁边,并指示部署应用程序的 IT 团队使用 MSIX 修改包 以部署由您的 GUI 助手生成的自定义配置文件.(查看上面包含的链接以获取示例 - 文章末尾有视频版本).

You can still leave the config file next to the EXE, in ProgramFiles and instruct the IT teams that deploy the app to use an MSIX Modification Package to deploy the custom config file generated by your GUI helper. (check the link included above for an example - with a video version at the end of the article).

注意:IT 团队可以使用多种免费或付费工具来生成 MSIX 修改包.

当然,您的 GUI 助手工具仍然需要在允许的文件夹中生成该自定义配置文件,因为它不能再在 ProgramFiles 下写入.所以实际上,在这种情况下,您也确实需要稍微修改一下代码.

Of course, your GUI helper tool still needs to generate that customized config file in a folder where it is allowed, as it can no longer write under ProgramFiles. So actually, you do need to modify a little bit your code in this scenario too.

这篇关于如何使用 MSIX 允许可编辑的 .Net 生成配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆