Deployment in 2.0 - How To Not Overwrite web.config

G

Guest

I have what I think should be a pretty common scenario in a corporate
environment. I have a web app and three environments on three servers:
Development, QA and Production.

We develop in development and then deploy the updated application to our QA
server and then once tested to our production server.

The application has a web.config file. The contents of the file
(appsettings part) are different in all three environments because each
enviroment connects to different databases (a dev, qa and the prod database).

what I'm discovering is that the Publish option in VS2005 won't work in this
scenario because it will copy web.config from development to QA or production
and thus result in the incorrect appsettings...i.e. Production all of a
sudden connecting to the development database.

Is there any way around this with the Publish command? Or do i have to
manually use "Copy Web" which is more timeconsuming?

Excluding web.config does't work because the web.config in the destination
is still wiped out. I tried setting web.config to Read ONly in QA and
production but it is still deleted and overwritten by the one from dev.

Seems like someone really didn't think of this common scenario. An "Exclude
web.config" checkbox would have been all that was necessary. Or is this
hidden somewhere?

Thx.
R-
 
G

Greg Burns

Not sure if this applies, but have your looked at using a user.config file?
(I assume this still works in 2.0?)

user.config
<appSettings>
<add key="ConnectionString"
value="server=(local);Trusted_Connection=true;database=bar;Application
Name=foo" />
</appSettings>

web.config
<appSettings file="user.config">
<add key="ConnectionString"
value="server=PRODSERVER;Trusted_Connection=true;database=bar;Application
Name=foo"/>
</appSettings>

My basic understanding is if the user.config is present it will use it,
otherwise it defaults to the values in web.config. Not sure if Publish,
copies user.config to server or not. Something to look into, hopefully
somebody else has a better solution for you.

Greg
 
J

Juan T. Llibre

re:
An "Exclude web.config" checkbox would have been all that was necessary.

Doesn't selecting web.config in the Solution Explorer, and then going to the
menu "Website", and then clicking on "Exclude from project" work for you ?

What I would do, though, is include *all* connection strings in web.config and,
depending on the website's location, use the appropiate one.

Something like (pseudocode ) :

Dim dnsname As String = Request.Url.Host
If dnsname = domain1 Then
' request connection string 1 here
Elseif dnsname = domain2 Then
' request connection string 2 here
Else
' request connection string 3 here
End If
End If


That should take care of all your problems.
 
G

Guest

Thanks for your suggestion but it unfortunately is not an option in my case.

I tried using "exclude". When you use this, .net physically renames the
file in the dev site where i am developing to "web.config.exclude" which then
means that the dev site no longer works because there is no web.config.
Furthermore, when using the "publish" command, all of the files in the
destination are deleted first, irregardless of any "exclusion".

Even if I put all of the connection strings in the same web.config so it
could be identical in each environment i would still need to have a way to
know which environment i was actually running in and this would mean
hardcoding the url for example in a compiled file. Additionally in the
corporate environment where I am it is not permissible that I stored the
production credentials on the dev and qa sites although i do encrypt them.
And in some cases, i may not be allowed to know the production database
credentials which precludes them being the web.configs in each environments.

I think there really should have been a setting under options that just said
"exclude web.config" from publishing. And if checked, it 1) didn't delete a
web.config and 2) didn't copy or overwrite it either.

I am able to use the "copy web" to still deploy but it is significantly
slower than using publish and slower than the process under vs 2003.
Although theoretically if i just need to transfer a file or two, that is
faster.

thx.
r-
 
J

Juan T. Llibre

re:
Even if I put all of the connection strings in the same web.config so it
could be identical in each environment i would still need to have a way to
know which environment i was actually running in and this would mean
hardcoding the url for example in a compiled file.

No, no, no !

The pseudocode I outlined would work in all 3 environments,
providing the correct connection string to all of them.

re:
And in some cases, i may not be allowed to know the production database
credentials which precludes them being the web.configs in each environments.

You should talk your web admins about the inadvisability of that.

If you are tasked with developing a production site,
it's only natural that you have access to the databases there.

Anything less than that only hobbles you...and not even they want that.


re:
I am able to use the "copy web" to still deploy but
it is significantly slower than using publish

I'll take that any day over not being able to do it at all.

;-)
 
G

Guest

Obviously I'll have to stick with Copy Web. I work for a financial
institution (bank) and there are very strict government regulations so
security is currently a very, very big concern.

Thanks for your suggestions!
 
G

Greg Burns

http://dvxp.com/discus/messages/1/149.html?1071180598

This is interesting. The recommendation here is to put the user.config file
on the production server and not on the development server. That way you
don't have to worry about it being copied at all.

Does Publish really purge the destination folder first? I can't get it to
do that will my quick test.

Greg
 
G

Greg Burns

I guess my test was a little too quick. I see that it DOES purge first.
bummer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top