创建安装项目时如何使用最终的 {project}.exe.config 文件
我已经创建了一个控制台应用程序(blah.exe),其中包含用于开发和生产的特定 app.config。它们被命名为 dev_app.config
和 prod_app.config
。我已在 csproj 文件* 中连接了一个 AfterBuild
目标,它将正确的配置文件复制到 bin 目录,作为 blah.exe.config
。
我还为此控制台应用程序创建了一个安装项目,但遇到了一个小问题。看来安装项目使用项目目录中的实际 app.config
而不是最终的
|--Bin
| |--Debug
| |--Blah.exe.config <--- I want the setup project to use this file
|--app.config <--- Setup project uses this file at the moment
|--dev_app.config
|--prod_app.config
如何强制安装项目使用 bin 文件夹中生成的最终配置文件而不是实际的 app.config
文件?
其他信息:
我当前的解决方案涉及添加另一个 AfterBuild
命令,该命令会覆盖实际的 app.config
文件。我不喜欢这种方法,因为它迫使我有一个我不需要的额外文件。另外,自从我对 app.config
文件进行了更改(该文件在构建时被覆盖)以来,这个文件已经给我带来了一些痛苦。问题是如何让安装项目使用 bin 文件夹中的最终配置文件,而不是如何管理配置或创建配置文件的方法。
*< /sup> 改编自根据构建配置部署 app.config
I have created a console application (blah.exe) with specific app.config's for dev and prod. These are named dev_app.config
and prod_app.config
. I have hooked up an AfterBuild
target in my csproj file* which copies the correct config file to the bin directory as blah.exe.config
.
I have also created a setup project for this console app but I have run into a slight issue. It seems that the setup project uses the actual app.config
from the project directory as opposed to the final blah.exe.config
(located in bin directory).
|--Bin
| |--Debug
| |--Blah.exe.config <--- I want the setup project to use this file
|--app.config <--- Setup project uses this file at the moment
|--dev_app.config
|--prod_app.config
How can I force the setup project to use the final config file generated in the bin folder and not the actual app.config
file?
Additional Information:
My current solution involves adding another AfterBuild
command which overwrites the actual app.config
file. I don't like approach since it forces me to have an additional file that I don't need. Also, having this file has caused me some grief already since I made changes to the app.config
file which got overwritten when building. The question is about how to get the setup project use the final config file in the bin folder and NOT how to manage the config or ways to create a config file.
* Adapted from Deploy an app.config based on build configuration
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一直在使用完全相同的场景,但我使用 BeforeBuild 而不是 AfterBuild,而且一直都很好。我一直在 Web 和 Windows 项目上这样做。下面是我正在使用的代码。
希望这有帮助。
I have been using that exact same scenario but I use the BeforeBuild instead of AfterBuild, and it has always been fine. I have been doing this on both web and windows projects. Below is the code I am using.
Hope this helps.