7

I have defined my configSource to look for config files in a sub-directory called config, as follows:

<connectionStrings configSource="config\ConnectionStrings.config" />

I have the config file defined as a linked file, so when the build happens it gets copied into my bin\config folder just fine.

However, my web app projects are looking at the development project config folder instead of the deployment bin\config folder. I confirmed this with Process Monitor.

So I have several questions:

  1. Why is it looking there instead of bin\config - did I miss a relative path setting somewhere?
  2. The linked files are not copied there but to bin only. My understanding is that this is the proper behavior. Is that a correct assumption or should it be copied to both locations? If so, what is the setting to enable that?
  3. Is it good practice to use a sub-folder for linked files or should I leave them in the project root?

Thanks much!

UPDATE: I am using the method described here: http://consultingblogs.emc.com/jamesdawson/archive/2008/06/03/using-linked-files-with-web-application-projects.aspx to ensure that the config files are copied, and doing a little experimentation I have answered question #2. No it is not default behavior in Visual Studio but this work-around ensures the files are copied to both locations.

Shanerk
  • 5,175
  • 2
  • 40
  • 36

1 Answers1

2

I believe this may help you a little bit. How to use multiple Web.config files

Basically you can have as many config files as you like, as long as they are in separated folder of your web application. I a bit confused by part of your comment where you mention "different web project", could you be a bit more specific in that department? Also, I have found far more detail about this on msdn, I suggest you check it out.

Happy coding!

Мitke
  • 310
  • 3
  • 17
  • Well, I don't think I use the phrase "different web project" but I do have multiple target projects (3 web projects and one console app) which use the linked file ConnectionStrings.config. The question isn't how many config files. What I don't like is that the web projects are looking in my development path versus the deployment path for the config files. The Console app is not doing so. My expectation is that the web.config will look for the linked files in the deployment path once compiled, just as the app.config of my console app does. Sorry for the lack of clarity! – Shanerk Aug 10 '12 at 19:38
  • 1
    Hi again, well if I understood your question correctly, the only problem here is that web.config is not reading the linked file from the expected location. From what I could dig up , it seems that exact file location needs to be specified, in order for web.config to read it. Here is my [link](source of information: http://stackoverflow.com/questions/2411184/can-a-web-config-read-from-an-external-xml-file) – Мitke Aug 10 '12 at 21:33
  • Hi again, well if I understood your question correctly, the only problem here is that web.config is not reading the linked file from the expected location. From what I could dig up , it seems that exact file location needs to be specified, in order for web.config to read it. Here is my [source of information][1][1]:http://stackoverflow.com/questions/2411184/can-a-web-config-read-from-an-external-xml-file In my projects I actually use this approach, hopefully this may solve your problem. – Мitke Aug 10 '12 at 21:41
  • 1
    Thanks yes, I did read that article. As you can see it is not an absolute path but a relative one, that is why you can only specify the configSource as being within or below the same directory. When I deploy I expect the software to start at the deploy root and not need to know about the development root - obviously I won't have my source code on the server, right? So, perhaps this is only a problem when debugging, but why would my app need to know anything about my source code folder even in that case? – Shanerk Aug 10 '12 at 21:42