Visual Studio:区分调试和发布模式的 app.config
在发布模式下构建时,有没有办法自动使用单独的 app.config?
换句话说,我想使用一个 app.config 进行测试,然后使用另一个 app.config 进行发布。
目前,我保留一个名为 app.config.production 的单独副本,并在构建发布后手动覆盖 bin\Release\Application.exe.config。
Is there a way to automatically use a separate app.config when building in release mode?
In other words, I want to test with one app.config, and release with another.
Currently, I keep a separate copy called app.config.production, and manually overwrite bin\Release\Application.exe.config after building for release.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
通过上下文菜单在解决方案资源管理器中卸载项目。
通过上下文菜单编辑
.csproj
文件并添加以下内容:Unload the project in Solution Explorer via the context menu.
Edit the
.csproj
file via the context menu and add this:一个干净的解决方案是将 2 个文件
App.Debug.config
和App.Release.config
分组到App.config
中,并将好的文件更改为App.config
取决于编译时的配置:使用此解决方案,您将在 Visual Studio 中得到类似以下内容:
A clean solution is to group 2 files
App.Debug.config
andApp.Release.config
intoApp.config
and change the good file intoApp.config
depending on the configuration at compile time:With this solution you will get something like this in Visual Studio:
一种简单快速的方法是创建第二个文件“App.release.config”并插入此预构建事件:
以及此构建后事件:
这可能有点奇怪,但它允许您继续使用
.Settings
文件作为调试设置,仍然链接到App.config
。App.release.config
必须手动构建,但切换此功能非常容易。A simple and fast way is to create a second file "App.release.config" and insert this pre-build event:
And this post build event:
This might be a bit odd, but it will allow you to keep using the
.Settings
files as debug settings, that are still linked to theApp.config
. TheApp.release.config
must be build by hand, but it's pretty easy to switch this functionality.我强烈推荐 SlowCheetah 进行 app.config 转换。在此处访问此 nuget gem Visual Studio Gallery
I highly recommend SlowCheetah for app.config transformations. Visit this nuget gem here Visual Studio Gallery
与最佳答案类似,但通过这种方法,如果愿意,您可以看到实际文件,并且智能感知不会在 csproj 文件中抱怨:
Similar to top answer but with this approach you can see the actual file if preferred and intellisense doesn't complain in csproj file:
我不知道这是否有帮助,但 app.config 将识别标准 MSBUILD 替换字符串,例如 $(Configuration)。
I don't know if this helps, but app.config will recognise the standard MSBUILD substitution strings such as $(Configuration).