2

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.

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).

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.

We are using Visual Studio 2008 with VSS.

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

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
if errorlevel 1 goto AttribFailed

copy $(ProjectDir)app.config.$(ConfigurationName) $(ProjectDir)app.config
goto BuildOK

:AttribFailed
echo Attrib -r Failed on $(ProjectDir)app.config
exit 1

:BuildOK
echo Copy Done

Jacob Hulse
  • 839
  • 1
  • 10
  • 19

2 Answers2

1

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.).

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.)

Jeff Sternal
  • 47,787
  • 8
  • 93
  • 120
  • If app.config is not in the solution and not under source control, then it is not used when building the application and I do not have access to the config string. I will try making it writable prior to the build events without checking the file out. – Jacob Hulse Mar 16 '11 at 15:56
  • Updated the Pre-Build event to make the file writable did the trick. Thank you @HansPassant for your suggestion. – Jacob Hulse Mar 16 '11 at 16:18
1

Leaving the .config files checked-in has one side-effect, the files stay read-only. Which has one side-effect, you cannot copy a file over a read-only file and you can't delete it. Which goes a long way towards explaining why you can't make it work.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536