我在
Windows Forms
中开发了一个 VS2022
应用程序,其中有几个 int 类型的 User Settings
,以便当用户修改某些参数时,它们的值将被保存并在下一次应用程序执行中加载。这在我的项目中生成了一个具有 App.config
和 Build Action->None
属性的 Copy to Output Directory->Do not copy
xml 文件。
当我发布我的应用程序(使用发布选项
Produce single file
)时,我的输出目录中会生成 3 个文件:.exe
、.pdb
和 .dll.config
文件。
如果我将
.exe
移动到其他文件夹,启动它时会抛出以下异常:
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize`
所以它似乎依赖于与
.dll.config
文件位于同一目录中。
我尝试将
App.config
s Build Action
设置为 Embedded Resource
但它仍然引发异常,这种依赖关系有解决方法吗?
您可以尝试添加
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
进入 pubxml 文件。