gpt4 book ai didi

.net - 使用 ILMerge 后无法读取自定义配置部分

转载 作者:行者123 更新时间:2023-12-01 11:29:29 32 4
gpt4 key购买 nike

主题:我创建控制台应用程序(文档解析器)并使用 NLog 记录处理事件。构建后,我使用 ILMerge 工具将所有 DLL 合并到一个可执行文件(它需要更舒适地使用结果工具)

如果我使用外部 NLog.config xml 文件进行记录器配置 - 它工作正常(在将所有 dll-s 和 exe 合并到单个文件之前和之后)

所以,问题:但是,如果我尝试在 docsloader.exe.config 文件中使用“nlog”部分 - 它只能在不通过 IL 合并的情况下工作(如果所有 dll 和 exe 文件都处于单独模式)。如果我首先将结果合并到单个文件并运行 docsloader.exe,我会看到:

Unhandled Exception: System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for nlog: Could not load file or
assembly 'NLog' or one of its dependencies. The system cannot find the file specified. (C:\d\projects\_\out\docsloader.exe.Config line 5)
---> System.IO.FileNotFoundException: Could not load file or assembly 'NLog' or one of its dependencies. The system cannot find the file specified.

docsloader.exe.config(前 20 个字符串)

<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
<targets>
<target name="console" type="Console" layout="${date:format=HH\:mm\:ss}|${level}| ${message}" />
<target name="file" type="File" fileName="${basedir}/docsloader.log" layout="${date}|${level}| ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="console" />
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>

....

ILMerge 命令:

C:\d\projects\_\ILMerge\ILMerge.exe /out:"C:\d\projects\_\_\out\docsloader.exe" "C:\d\projects\_\_\bin\Release\docsloader.exe" "C:\d\projects\_\_\bin\Release\*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /lib:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /wildcards

echo Coping docsloader.exe.config...
cp C:\d\projects\_\_\bin\Release\docsloader.exe.config C:\d\projects\_\_\out\docsloader.exe.config

PS:如果我删除 -section 并创建 NLog.config - 它工作正常。谢谢!

最佳答案

错误来自类型引用 NLog.Config.ConfigSectionHandler, NLog 引用 NLog dll(在逗号之后),它不再存在,因为它现在已合并.

您可以将其替换为 NLog.Config.ConfigSectionHandler, docsloader,它可能会起作用。

关于.net - 使用 ILMerge 后无法读取自定义配置部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090488/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com