我有一个附加到 app.config 的设置文件,并且我正在使用预构建命令行来调用一个 bat 文件,该文件假设根据项目的所选配置(调试、发布 . ..) 在构建过程之前。一切看起来都不错,app.config 在构建时得到更新(我可以看到设置和 app.config 中的更改)。但是当我尝试使用如下命令获取设置中的任何值时:
var test = Settings.Default.DBConn;
但是...第一次(app.config 没有被覆盖)一切正常,但是当我更改配置时(假设从调试到发布)会抛出一个错误,表明出现了问题使用 xml 或类似的内容,错误是 ConfigurationErrorsException,消息是
The value of the property 'serializeAs' cannot be parsed. The error is: The enumeration value must be one of the following: String, Xml, Binary, ProviderSpecific.
这是我的bat文件:
@echo off
if %1==Debug GOTO DE
if %1==DEV GOTO DEV
if %1==Release GOTO PR
:DE
xcopy %2configs\app_Debug.config %2app.config /Y
GOTO END
:PR
xcopy %2configs\app_PROD.config %2app.config /Y
GOTO END
:DEV
xcopy %2configs\app_DEV.config %2app.config /Y
GOTO END
:END
我真的不知道问题是什么,我查看了这些讨论
Overriding App.Config settings
Manage multiple app config files during development
还有更多。但我找不到任何解决办法。 你能帮我解决这个问题吗? 谢谢。
最佳答案
有一个名为 SloWCheetah 的 Visual Studio 扩展就是为此目的而设计的。它允许您为每个构建配置提供 XSLT 转换到 app.config。看看http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5
关于c# - 覆盖预构建和使用设置中的 App.Config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23020124/