发生预构建事件后,App.Config被忽略 [英] App.Config Ignored After Pre-Build Event

查看:74
本文介绍了发生预构建事件后,App.Config被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个项目和多个开发人员的解决方案,每个开发人员都有自己的环境(当然).为了管理每个环境之间的连接字符串,我为每个环境创建了几个app.config文件:app.config.dev,app.config.qa等.

I have a solution with several projects and several developers, each with their own environment (of course). To manage connection strings between each environment, I have created several app.config files for each environment: app.config.dev, app.config.qa, etc.

构建前事件只是将app.config.$(ConfigurationName)复制到app.config.此预构建事件是针对解决方案中的每个项目完成的,并且连接字符串包含在每个项目中(包括测试项目).

The pre-build event simply copies the app.config.$(ConfigurationName) to app.config. This pre-build event is done for each project in the solution, and the connection string is included in each (including the test project).

当我使用预生成事件来管理app.config文件时,找不到连接字符串.我可以通过2种方法使测试正常运行:1.不要使用构建前事件来管理app.config文件的选择,而是自己或2.进行检查.如果我检出app.config并使它可写,那么预构建事件就可以正常工作.

When I use the pre-build events to manage the app.config files, the connection string cannot be found. I can get the tests to run fine by 2 methods: 1. Do not use the pre-build events to manage the app.config file selection, and do it myself or 2. If I check out app.config and make it writable, then the pre-build events work just fine.

我们正在将Visual Studio 2008与VSS一起使用.

We are using Visual Studio 2008 with VSS.

我在这里是我的最后一头白发,有什么想法吗?预先感谢!

I'm down to my last grey hair here, any ideas? Thanks in advance!

解决方案更新预构建事件以确保app.config文件即使已签入也是可写的.预构建事件在下面使用:
@echo off

SOLUTION Update the pre-build event to ensure the app.config file is writable even if it is checked in. Pre-Build event used below:
@echo off

attrib -r $(ProjectDir)app.config
如果错误级别为1,请转到AttribFailed

复制$(ProjectDir)app.config.$(ConfigurationName)$(ProjectDir)app.config
转到BuildOK

:AttribFailed
echo Attrib -r在$ {ProjectDir)app.config上失败
退出1

:BuildOK
echo复制完成

推荐答案

听起来您的app.config不应受到源代码控制-只是特定于构建配置的配置文件(app.config.dev,app.config.qa等).

It sounds like your app.config shouldn't be under source control - just the build-configuration-specific configuration files (app.config.dev, app.config.qa, etc.).

话虽如此,您可以使签入文件在VSS下可写.例如,通过Windows资源管理器,取消选中文件的只读"属性.(每次签入时,您都必须这样做.)

Having said that, you can make checked-in files writable under VSS. For example, through windows explorer, uncheck the file's "Read-only" attribute. (You'll have to do this each time you check it in.)

这篇关于发生预构建事件后,App.Config被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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