【发布时间】:2019-12-22 15:28:56
【问题描述】:
我正在使用目标框架 .NET 2.0 处理遗留项目(Windows 窗体应用程序)。目标是构建一个不依赖于任何配置文件的.exe 文件(特别是不依赖于.exe.config,因为应用程序不需要此配置文件中的任何内容)。
项目特点:
Application:
Targe framework: .NET Framework 2.0
Output type: Windows Application
Auto-generate binding redirecs: Not enabled
Build:
Platform target: Any CPU
Visual Studio Community 2019, version 16.1.3
该解决方案有一个 app.config 文件,我试图删除它,但由于某种原因它似乎仍保留在项目中。当我说 似乎 留在项目中是因为我遵循以下步骤:
- 在解决方案资源管理器中,右键单击
App.config,然后单击从项目中排除。 - 重建项目,仍然生成
.exe.config。 - 再次在解决方案资源管理器中 > 添加 > 新项目,当我尝试添加名称为
App.config的应用程序配置文件时,VS 显示此消息:名称为“App.config”的文件已存在.要更换吗?。
(我也试过右击App.config,然后点击删除选项)
这似乎表明配置文件没有有效地从项目中删除,因此仍然会生成.exe.config。
另外,我检查了这个post,并尝试更改文件属性(构建操作、复制到输出目录等)但.exe.config文件保留在构建中。
最后,我尝试(可能更多是绝望的尝试)取消选中 自动生成绑定重定向,这会阻止.exe.config 的生成,但.exe 运行不正常.
作为附加信息,.exe.config 的内容是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Company.Afis.ImageContainer" publicKeyToken="97cac07b8409e999" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.0.1827" newVersion="2.5.0.1827" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我检查过的其他帖子:
- How to make work 'do not copy' app.config to output directory?
- appname.exe.config not created on windows application
- Release build without config file
- How to not copy app.config file to output directory
如果需要任何其他信息,请告诉我更新。
【问题讨论】:
-
您可以禁用程序集绑定并使用
AppDomain.AssemblyResolve。 -
pdb 文件怎么样?你有他们禁用吗?我问是因为我不确定你为什么要禁用 exe.config-files。要让 clean
Bin文件夹里面只有一个 exe?其他文件是否会导致问题?哪个问题? -
@Reza Aghaei 我正在检查,谢谢。 @Sinatr,我已启用/禁用调试信息,但它不影响
.exe.config。想法是拥有一个不依赖于任何其他文件的.exe文件,所以是的.. 拥有一个干净的Bin文件夹。至于问题,如果我删除.exe.config文件,.exe将无法正常运行。
标签: c# visual-studio winforms build