如何在DLL而不是exe上使用app.config [英] how to use app.config on the DLL instead of exe

查看:48
本文介绍了如何在DLL而不是exe上使用app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个姐妹问题,同时也是我的第一个问题

This is a sister question along with my first question Allow C# application built with .NET 2.0 to run on .NET 4.0/4.5. I simplified my situation a little bit there for understanding. Actually our case is a little special.

基本上,我们为MSI安装程序编写了一个C#DLL(我们称为 E.dll ).由于我们的MSI安装程序正在使用Windows安装程序的较早版本,因此它无法直接使用C#DLL,并且只能与C类型的DLL一起使用,因此我们使用了一个名为

Basically we wrote a C# DLL (Let's call E.dll) for our MSI installer. Since our MSI installer is using older version of windows installer, it could not use C# DLL directly and it could only work with C type DLL, so we use an open source library called DLLExporter to generate the C export function entry port. The E.dll is built with .NET 2.0 (VS2005).

正如我的第一个问题所述,我们很难在仅安装.NET 4.0或更高版本的计算机上运行安装程序.经过这个出色的论坛的努力和帮助之后,我认为我开始了解这个问题,这是最终的应用程序配置文件:

As my first question is stated, we have trouble to run our installer on machine where only .NET 4.0 or above is installed. After some effort and help from this excellent forum as well, I think that I started to understand the issue, and here is the final application configuration file:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v2.0.50727"/>    
  <supportedRuntime version="v4.0"/>        
</startup>

由于这些C导出函数入口点,最终的C#dll被认为是混合模式程序集,因此在.NET 4.0上我需要将useLegacyV2RuntimeActivationPolicy设置为"true".

Due those C export function entry point, the final C# dll is considered a mixed mode assembly, so I need the useLegacyV2RuntimeActivationPolicy as "true" on .NET 4.0.

但是,只有一个问题,该配置必须在exe上,而不是在DLL上.我通过使用测试工具exe确认了这一点,该工具可以像我们的MSI一样动态加载 E.dll .让我们将测试工具exe称为 T.exe .因此,通过具有上述的 E.dll.config 内容将无济于事.我们需要 T.exe.config 文件.但是,对于我们的MSI安装程序,它是msiexe.exe,它位于 C:\ windows \ system32 中,我们无法将名为 msiexe.exe.config 的文件放入system32中(我刚刚对其进行了测试,但它无法正常工作,我仍然需要弄清楚应该使用哪个app.config文件作为exe文件).不管哪个exe,都是一团糟.我将无法通过在.NET 4.0(VS2010)中构建DLL来解决此问题,因为我需要配置文件才能将useLegacyV2RuntimeActivationPolicy设置为"true".

However there is one issue, the configuration has to be on the exe, but not on the DLL. I confirmed this by using a test harness exe which dynamically loads the E.dll like our MSI. let's call test harness exe as T.exe. So by having E.dll.config as above content won't help. We need the T.exe.config file. However for our MSI installer, it is msiexe.exe which is located at C:\windows\system32 and we can not put a file called msiexe.exe.config into system32 (I just tested it and it doesn't work and I still need to figure out which exe I should have the app.config file). No matter which exe, it is a mess. I won't be able to solve this problem by building the DLL in .NET 4.0 (VS2010) since I would need the config file to set useLegacyV2RuntimeActivationPolicy to "true".

有什么主意,我该如何在DLL而不是exe上放置app.config?

Any idea how I could have the app.config on the DLL instead of on exe?

推荐答案

我的建议是使用蹦床.EXE生成.NET DLL进程外.

My recommendation would be to use a trampoline .EXE to spawn the .NET DLL out-of-process.

由于msiexec.exe具有嵌入式清单,因此msiexec.exe.config不起作用.

The msiexec.exe.config didn't work because msiexec.exe has an embedded manifest.

这篇关于如何在DLL而不是exe上使用app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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