如何使工作“不复制” app.config到输出目录? [英] How to make work 'do not copy' app.config to output directory?

查看:179
本文介绍了如何使工作“不复制” app.config到输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么:


  1. 创建新的WPF应用程序项目

  2. 添加App.config

  3. 构建项目

  4. 打开App.config属性并将复制到输出目录参数设置为不复制

  5. App.config
  6. 进行一些更改。
  7. 转到 bin\Debug 文件夹并将只读属性设置为文件 WpfApplication1.exe.config

  8. 重建项目

结果:

 错误2无法将文件 App.config复制到 bin\ 调试 WpfApplication1.exe.config。拒绝访问路径 bin\Debug\WpfApplication1.exe.config。 WpfApplication1 

为什么VS仍在尝试复制文件,以及如何强制其停止执行此操作? / p>

PS我正在多台远程计算机上调试我的应用程序(根据需要在它们之间切换),每台计算机都应具有自己的配置。这就是为什么我不希望VS覆盖每个构建版本的原因。

解决方案

App.config的默认值为不复制,并且不会在该构建过程的该部分中复制。
如果您想要不同版本的构建(Debug_1,Debug_2,...),请根据构建的不同,使用构建前事件脚本将App.config.debug_1或App.config.debug_2,...复制到App.config中。



我认为您不能更改Visual Studio复制app.config的方式。但是我认为这可能是您的解决方案。把它放在程序的开始。

  #if DEBUG_1 
AppDomain.CurrentDomain.SetData( APP_CONFIG_FILE, debug_1.config);
#endif
#if DEBUG_2
AppDomain.CurrentDomain.SetData( APP_CONFIG_FILE, debug_2.config);
#endif
...

这种方式将复制配置文件,但它不会被使用。只需复制该配置并进行所需的更改即可。


What I am doing:

  1. Create new WPF Application project
  2. Add App.config to the project
  3. Build project
  4. Open App.config properties and set 'Copy to output directory' parameter to 'Do not copy'
  5. Make some changes to App.config
  6. Go to bin\Debug folder and set read-only attribute to file WpfApplication1.exe.config
  7. Rebuild project

Result:

Error   2   Unable to copy file "App.config" to "bin\Debug\WpfApplication1.exe.config". Access to the path 'bin\Debug\WpfApplication1.exe.config' is denied.    WpfApplication1

Why VS still trying to copy the file, and how to force it to stop doing this?

P.S. I'm debugging my app on several remote computers (switching between them as needed) and each one should have it's own configuration. That's why I don't want VS to overwrite configuration on each build.

解决方案

Default for App.config is "do not copy", and it is not copied in that part of that build process. If you want different versions for builds ( Debug_1, Debug_2,... ) make pre-build event script to copy App.config.debug_1 or App.config.debug_2,... to App.config depending on build type.

I don't think you can change the way visual studio copies app.config. But I think this might be solution for you. Put this at the beginning of your program.

#if DEBUG_1
    AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "debug_1.config");
#endif
#if DEBUG_2
    AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "debug_2.config");
#endif
...

This way config file will be copied, but it wont be used. Simply copy that config and make changes you need.

这篇关于如何使工作“不复制” app.config到输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆