Jas*_*onS 7 .net installer app-config wix dtf
我发现一个例子在安装过程中加密的web.config 这里,但我的应用程序是一个Windows服务.该aspnetreg_iis方法仅适用于web.config文件.
我知道如何以编程方式加密配置文件,但我不认为我可以使用WiX做到这一点.我错了吗?有任何想法吗?
您应该能够在自定义操作中完成此操作。我发现的问题是加载 ExeConfigurationFileMap 的程序集会引发异常,但您可以通过向 AppDomain 添加 AssemblyResolve 处理程序来处理该异常。这是我编写的富客户端应用程序的一种破解,用于使用机器加密密钥加密/解密受保护的配置部分。这可能不是最漂亮的代码,但我希望您能从中得到启发。此代码假设您在配置文件中定义了要使用的 ProtectionProvider。
//class global
static System.Reflection.Assembly DefiningAssembly;
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
static System.Reflection.Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
return DefiningAssembly;
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以像这样加载配置:
DefiningAssembly = System.Reflection.Assembly.LoadFrom("path to defining assembly for config");
//Set the Configuration using an ExeConfigurationFileMap - This works for any .config file.
ExeConfigurationFileMap CfgMap = new ExeConfigurationFileMap();
CfgMap.ExeConfigFilename = "path to config file";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(CfgMap, ConfigurationUserLevel.None);
List<string> DefiningAssemblyTypes = new List<string>();
foreach (System.Type type in DefiningAssembly.GetExportedTypes())
{
DefiningAssemblyTypes.Add(type.Name);
}
foreach (ConfigurationSection tempSection in config.Sections)
{
if (DefiningAssemblyTypes.Contains(tempSection.ElementInformation.Type.Name))
{
section = tempSection;
break;
}
}
ProtectionProviderName = section.SectionInformation.ProtectionProvider.Name;
section.SectionInformation.ProtectSection(ProtectionProviderName);
config.Save(ConfigurationSaveMode.Minimal, true);
Run Code Online (Sandbox Code Playgroud)
我希望这对你有帮助,祝你好运。