Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
How to share configuration files between projects

Sharing configuration files between multiple projects in Visual Studio is a simple task, but it is not intuitive in how it is done.  In fact, until recently I did not know how to do it via the IDE, I would always hand edit the .sln file to enable this feature (sad I know).  Today I thought I would throw up a simple set of screen shots to show everyone how easy it really is.

Overview:

We have a solution that has multiple projects and we would like to share our app.config along with our StructureMap.config files between each of the projects.

Step One -- Adding the config files to your soultion:

Create a solution folder in your solution.  I like to add them here as a way of organizing my common files.   Once you have your Solution folder created, right click and choose Add -> New Item (see blow) (If you already have these files, simple do an Add -> Existing item and reference the existing ones).

AddNewSolutionItem

Now for some odd reason MS decided that Application Configuration files were not a valid option for solution folders so we have to do some manual work.  Select the "Text File" template and rename the file to App.Config (see blow).

TextFileTempalte

Finally because we did not choose the Application Configuration template we need to add the XML tags to the file by hand. Here is the XML to add.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

Step Two - Add reference to the each project:

Now that we have created our config files in our solution folders we want to add them to each project.  We do this by right clicking the project and choosing Add -> Existing Item

AddExistingItem

This will open up a new dialog and this is where the magic happens (the part that always eluded me).  Change the extension type filter to 'All Files(*.*)" allowing us to see the .config files.  Choose the file you want to add, but don't click directly on the "Add" button.  Click the little drop down arrow on the right hand side.  This will give you 2 options.  1) Add 2) Add as Link.  Choose Add As Link.

AddAsLink

After you choose the 'Add as Link' option you will notice that the App.Config file will be added to your project.  But it will has the shortcut image on the icon, this tells you it is a link, not an actual reference.

ShowingAppConfigFile

Step Three -- Setting up the Properties on the file

After we have added our config file we need to ensure that it gets copied to our output (bin) directory during a compile.  *** NOTE *** You do NOT need to do this with an App.config or Web.config as the IDE will do it for you *** END NOTE ***

Right click the linked file and choose Properties.  This will open up a new dialog (fly out pane) and choose 'Copy Always' or 'Copy If Newer' in the Copy to Output Directory action.

CopyAlways

 

There you go, you now have a single config file for your solution that can be referenced by all the projects in your solution.

Hope this helps someone.

Till next time,


Posted 04-15-2008 7:47 AM by Derik Whittaker

[Advertisement]

Comments

Cornel wrote re: How to share configuration files between projects
on 04-15-2008 10:28 AM

Why not to add a App.settings file. The .settings file automatically generates the app.config and also you have the designer for adding new values. Am I wrong?

Chris wrote re: How to share configuration files between projects
on 04-15-2008 10:28 AM

lol

Someone: "Hey Derik, what did you work on today?"

Derik: "I PISS'd all day...it was awesome!"

Mike wrote re: How to share configuration files between projects
on 04-15-2008 10:55 AM

Thanks for sharing this Derik! This has eluded me and I hadn't had time to work it out

James Gregory wrote re: How to share configuration files between projects
on 04-15-2008 10:59 AM

Nice tip Derik, I was just cursing having to keep our 3 apps in sync. :)

Derik Whittaker wrote re: How to share configuration files between projects
on 04-15-2008 11:26 AM

@Cornel,

How does that help me share the config values across multiple projects.

Also, the IDE designer is no reason to use anything.  If you cannot edit by hand, and understand it you are going to be screwed the first time the designer f$%^'s up your file.

DotNetKicks.com wrote How to share configuration files between projects
on 04-15-2008 11:48 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

donnou wrote re: How to share configuration files between projects
on 04-15-2008 10:05 PM

A little off-topic... but I would like to know how to keep different configs among different developers (eg. connection strings) in the same project sharing a common app.config.

Jason Kealey wrote re: How to share configuration files between projects
on 04-15-2008 11:01 PM
Scott Isaacs wrote re: How to share configuration files between projects
on 04-16-2008 12:16 AM

Nice.  My way around it was to have an app.config "shell" in each project, with each node pointing to a separate file for its settings (connectionstrings.config, appsettings.config, etc.).  The I added a bud event to copy these files.  Your way is much simpler.

Reflective Perspective - Chris Alcock » The Morning Brew #74 wrote Reflective Perspective - Chris Alcock &raquo; The Morning Brew #74
on 04-16-2008 2:55 AM

Pingback from  Reflective Perspective - Chris Alcock  &raquo; The Morning Brew #74

Igor wrote re: How to share configuration files between projects
on 04-16-2008 6:07 AM

Thank you!

Derik Whittaker wrote re: How to share configuration files between projects
on 04-16-2008 6:07 AM

@Scott,

Have you noticed any issues with this when using R#.  I actually ran into issues yesterday when i added a external config for my app settings.

Derik Whittaker wrote How to have a Single Config File for multiple developers
on 04-16-2008 9:13 AM

In my last post I talked about how you can share a single config file among multiple project in a solution

Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew
on 04-16-2008 9:56 AM

Pingback from  Dew Drop - April 16, 2008 | Alvin Ashcraft's Morning Dew

Chinh Do wrote re: How to share configuration files between projects
on 05-12-2008 9:39 PM

Derik: Thanks for sharing. This will also work for sharing one AssemblyInfo.cs (for AssemblyVersion and FileVersion) file across projects.

pratap singh wrote re: How to share configuration files between projects
on 05-16-2008 7:37 AM

thanks dude,

it really resolves the issue of accessing the config file(linked) of a project in other project added to same solution.

but the becomes useless when the referring project itself contain its app.config file as in this situation CLR reads only one config file that is of referring project not the referred project and simply skips over the linked config files. i even tried to change the name of files like app.config and app1.config but it not at all reads the key of config file in the linked project.

can u help resolve this issue?

Finds of the Week - May 31, 2008 » Chinh Do wrote Finds of the Week - May 31, 2008 &raquo; Chinh Do
on 06-01-2008 10:51 PM

Pingback from  Finds of the Week - May 31, 2008 &raquo; Chinh Do

Ultracet medication. wrote Ultracet.
on 06-14-2008 10:15 PM

Ultracet.

Bill Roerts wrote re: How to share configuration files between projects
on 08-14-2008 11:52 AM

Still work'n in the ghetto...

Using VS2002, I don't have the option to copy the file to the BIN..

The COPY TO OUTPUT DIRECTORY option is not avail to me :(

DotNetShoutout wrote How to share configuration files between projects
on 11-20-2008 8:46 AM

Your Story is Submitted - Trackback from DotNetShoutout

.Net Articles wrote Sharing configuration files
on 12-04-2008 4:35 PM

Derik Whittaker has posted a blog post that I found recently via stackoverflow.com that demonstrates

majority times wrote re: How to share configuration files between projects
on 05-08-2009 5:40 AM

1800s cost new observational developer upper

Heel wrote re: How to share configuration files between projects
on 06-03-2009 2:54 AM
Jane wrote re: How to share configuration files between projects
on 06-20-2009 10:49 AM

<a href= http://italian+schools+in+italy.thanauts.info/ >italian schools in italy</a>  

<a href= http://the+royal+gazette+in+bermuda.thanauts.info/ >the royal gazette in bermuda</a>  

<a href= http://rain+forests+plants.thanauts.info/ >rain forests plants</a>  

<a href= http://fast+food+fact.thanauts.info/ >fast food fact</a>  

<a href= http://hotels+in+montana.thanauts.info/ >hotels in montana</a>  

<a href= http://download+mobile+software+free.thanauts.info/ >download mobile software free</a>  

<a href= http://my+country+tis+of.thanauts.info/ >my country tis of</a>  

<a href= http://hotel+kapiolani+queen.thanauts.info/ >hotel kapiolani queen</a>  

<a href= http://ball+bowling+brunswick.thanauts.info/ >ball bowling brunswick</a>  

<a href= http://parts+ford+focus.thanauts.info/ >parts ford focus</a>  

<a href= http://mood+rings+color.thanauts.info/ >mood rings color</a>  

<a href= http://backgrounds+neopets+shops.thanauts.info/ >backgrounds neopets shops</a>  

<a href= http://yankees+myspace+layouts.thanauts.info/ >yankees myspace layouts</a>  

<a href= http://denver+co+real+estate.thanauts.info/ >denver co real estate</a>  

<a href= http://anything+but+you.thanauts.info/ >anything but you</a>  

<a href= http://motor+vehicle+departments.thanauts.info/ >motor vehicle departments</a>  

<a href= http://cinque+italy+terre.thanauts.info/ >cinque italy terre</a>  

<a href= http://the+princess+cruise.thanauts.info/ >the princess cruise</a>  

<a href= http://cabin+rental+blue+ridge+mountains.thanauts.info/ >cabin rental blue ridge mountains</a>  

<a href= http://what+is+ascus.thanauts.info/ >what is ascus</a>

Jane wrote re: How to share configuration files between projects
on 06-20-2009 8:31 PM

<a href= http://mario+online+game.thanauts.info/ >mario online game</a>  

<a href= http://looking+for+business+partners+in.thanauts.info/ >looking for business partners in</a>  

<a href= http://www+tug+jobs.thanauts.info/ >www tug jobs</a>  

<a href= http://the+journal+entries.thanauts.info/ >the journal entries</a>  

<a href= http://caught+on+tape+fights.thanauts.info/ >caught on tape fights</a>  

<a href= http://different+breeds+of+dog.thanauts.info/ >different breeds of dog</a>  

<a href= http://american+apparel+clothing.thanauts.info/ >american apparel clothing</a>  

<a href= http://irs+form+941.thanauts.info/ >irs form 941</a>  

<a href= http://myspace+com+site+sophie.thanauts.info/ >myspace com site sophie</a>  

<a href= http://picture+of+a+pitbull.thanauts.info/ >picture of a pitbull</a>  

<a href= http://funny+text+messages+free.thanauts.info/ >funny text messages free</a>  

<a href= http://del+playa+rentals.thanauts.info/ >del playa rentals</a>  

<a href= http://entertainment+center+for+big+screen+tv.thanauts.info/ >entertainment center for big screen tv</a>  

<a href= http://the+good+guy.thanauts.info/ >the good guy</a>  

<a href= http://ass+bitch+hot.thanauts.info/ >ass bitch hot</a>  

<a href= http://hair+do+ideas.thanauts.info/ >hair do ideas</a>  

<a href= http://pop+up+stoppers.thanauts.info/ >pop up stoppers</a>  

<a href= http://army+blues+dress.thanauts.info/ >army blues dress</a>  

<a href= http://feel+it+to+be.thanauts.info/ >feel it to be</a>  

<a href= http://run+in+lyrics.thanauts.info/ >run in lyrics</a>

Diesel wrote re: How to share configuration files between projects
on 06-20-2009 8:50 PM

<a href= http://the+davinci+code+book+reviews.thanauts.info/ >the davinci code book reviews</a>  

<a href= http://bridge+to+peace.thanauts.info/ >bridge to peace</a>  

<a href= http://the+large+print.thanauts.info/ >the large print</a>  

<a href= http://sex+positions+photo.thanauts.info/ >sex positions photo</a>  

<a href= http://cd+easy+creator.thanauts.info/ >cd easy creator</a>  

<a href= http://when+a+man+love+woman+lyric.thanauts.info/ >when a man love woman lyric</a>  

<a href= http://wait+on+me+lyrics.thanauts.info/ >wait on me lyrics</a>  

<a href= http://all+the+best+with.thanauts.info/ >all the best with</a>  

<a href= http://free+view+webcams.thanauts.info/ >free view webcams</a>  

<a href= http://ford+trenton+new+jersey.thanauts.info/ >ford trenton new jersey</a>  

<a href= http://classics+collection+disney+walt.thanauts.info/ >classics collection disney walt</a>  

<a href= http://wonder+of+the+world.thanauts.info/ >wonder of the world</a>  

<a href= http://alligator+attack+deadly.thanauts.info/ >alligator attack deadly</a>  

<a href= http://what+was+the+big+bang+theory.thanauts.info/ >what was the big bang theory</a>  

<a href= http://real+estate+steamboat+springs+co.thanauts.info/ >real estate steamboat springs co</a>  

<a href= http://claim+jumper+restraunt.thanauts.info/ >claim jumper restraunt</a>  

<a href= http://the+boa+constrictor.thanauts.info/ >the boa constrictor</a>  

<a href= http://www+noble+collection.thanauts.info/ >www noble collection</a>  

<a href= http://do+jigsaw+puzzles.thanauts.info/ >do jigsaw puzzles</a>  

<a href= http://justin+and+cameron+diaz.thanauts.info/ >justin and cameron diaz</a>

Neo wrote re: How to share configuration files between projects
on 06-20-2009 10:16 PM

<a href= http://testing+for+asbestos.thanauts.info/ >testing for asbestos</a>  

<a href= http://foot+print+in+snow.thanauts.info/ >foot print in snow</a>  

<a href= http://charter+sailing+caribbean.thanauts.info/ >charter sailing caribbean</a>  

<a href= http://is+your+man+cheating.thanauts.info/ >is your man cheating</a>  

<a href= http://you+disappoint+me.thanauts.info/ >you disappoint me</a>  

<a href= http://free+gallery+sex.thanauts.info/ >free gallery sex</a>  

<a href= http://registration+for+the+act.thanauts.info/ >registration for the act</a>  

<a href= http://beyonce+myspace+com+site.thanauts.info/ >beyonce myspace com site</a>  

<a href= http://love+you+always+forever.thanauts.info/ >love you always forever</a>  

<a href= http://car+finance+in+uk.thanauts.info/ >car finance in uk</a>  

<a href= http://tattoo+laser+removal.thanauts.info/ >tattoo laser removal</a>  

<a href= http://what+do+electrical+engineers.thanauts.info/ >what do electrical engineers</a>  

<a href= http://answering+machine+message.thanauts.info/ >answering machine message</a>  

<a href= http://the+sims+makin+magic+cheat.thanauts.info/ >the sims makin magic cheat</a>  

<a href= http://hair+to+his.thanauts.info/ >hair to his</a>  

<a href= http://cooper+river+bridge.thanauts.info/ >cooper river bridge</a>  

<a href= http://leather+couches+and.thanauts.info/ >leather couches and</a>  

<a href= http://door+girl+im+just+next.thanauts.info/ >door girl im just next</a>  

<a href= http://books+about+time.thanauts.info/ >books about time</a>  

<a href= http://cafe+camilles+sidewalk.thanauts.info/ >cafe camilles sidewalk</a>

Diesel wrote re: How to share configuration files between projects
on 06-20-2009 10:56 PM

<a href= http://how+to+do+homework.thanauts.info/ >how to do homework</a>  

<a href= http://thank+you+for+the+interview+samples.thanauts.info/ >thank you for the interview samples</a>  

<a href= http://stand+united+we.thanauts.info/ >stand united we</a>  

<a href= http://pa+sex+offender.thanauts.info/ >pa sex offender</a>  

<a href= http://leads+for+life+insurance.thanauts.info/ >leads for life insurance</a>  

<a href= http://skin+beauty+care.thanauts.info/ >skin beauty care</a>  

<a href= http://sailor+moon+online+games.thanauts.info/ >sailor moon online games</a>  

<a href= http://colors+mood+rings.thanauts.info/ >colors mood rings</a>  

<a href= http://diamond+stud+earrings.thanauts.info/ >diamond stud earrings</a>  

<a href= http://prepaid+cell+phones+with.thanauts.info/ >prepaid cell phones with</a>  

<a href= http://dj+site+myspace+com.thanauts.info/ >dj site myspace com</a>  

<a href= http://scores+for+the+nfl.thanauts.info/ >scores for the nfl</a>  

<a href= http://bumps+on+vagina.thanauts.info/ >bumps on vagina</a>  

<a href= http://rachel+mcadams+ryan+gosling+dating.thanauts.info/ >rachel mcadams ryan gosling dating</a>  

<a href= http://adult+game+video.thanauts.info/ >adult game video</a>  

<a href= http://cruise+ships+to+alaska.thanauts.info/ >cruise ships to alaska</a>  

<a href= http://www+micheal+jordan.thanauts.info/ >www micheal jordan</a>  

<a href= http://big+cock+sucker.thanauts.info/ >big cock sucker</a>  

<a href= http://what+is+a+symbiotic+relationship.thanauts.info/ >what is a symbiotic relationship</a>  

<a href= http://recipes+southern+cooking.thanauts.info/ >recipes southern cooking</a>

Neo wrote re: How to share configuration files between projects
on 06-20-2009 11:21 PM

<a href= http://hampshire+new+tourism.thanauts.info/ >hampshire new tourism</a>  

<a href= http://atx+case+micro.thanauts.info/ >atx case micro</a>  

<a href= http://holmes+katie+nude.thanauts.info/ >holmes katie nude</a>  

<a href= http://you+and+only+lyrics.thanauts.info/ >you and only lyrics</a>  

<a href= http://huge+tit+anime.thanauts.info/ >huge tit anime</a>  

<a href= http://prada+sunglasses+men.thanauts.info/ >prada sunglasses men</a>  

<a href= http://www+investors+business+daily.thanauts.info/ >www investors business daily</a>  

<a href= http://media+player+skin+window.thanauts.info/ >media player skin window</a>  

<a href= http://black+gay+chat.thanauts.info/ >black gay chat</a>  

<a href= http://peace+nobelist+1993.thanauts.info/ >peace nobelist 1993</a>  

<a href= http://cheat+codes+the+sims+2+ps2.thanauts.info/ >cheat codes the sims 2 ps2</a>  

<a href= http://compound+interest+formulas.thanauts.info/ >compound interest formulas</a>  

<a href= http://crime+rates+by+city.thanauts.info/ >crime rates by city</a>  

<a href= http://minute+travel+deal.thanauts.info/ >minute travel deal</a>  

<a href= http://albuquerque+homes+for+sale.thanauts.info/ >albuquerque homes for sale</a>  

<a href= http://flirting+how+to.thanauts.info/ >flirting how to</a>  

<a href= http://date+jordans+new+release.thanauts.info/ >date jordans new release</a>  

<a href= http://baked+tilapia+recipie.thanauts.info/ >baked tilapia recipie</a>  

<a href= http://hinsdale+south+high.thanauts.info/ >hinsdale south high</a>  

<a href= http://map+mediterranean+sea.thanauts.info/ >map mediterranean sea</a>

Kir wrote re: How to share configuration files between projects
on 08-12-2009 2:17 AM

<a href= roseburgnewsreview.alsooufs.info >roseburg news review</a>  

<a href= http://scaricagiochigratis

Neo wrote re: How to share configuration files between projects
on 10-05-2009 8:21 PM
Dominic wrote re: How to share configuration files between projects
on 10-15-2009 4:21 AM

<a href= peleascallejerasgratis.vbtitliu.cn >peleas callejeras gratis</a>  

<a href= http://c

Sebastien wrote re: How to share configuration files between projects
on 10-15-2009 4:05 PM

Hey! Great help and easy using. I have some issues trying to modify it on runtime.

As the FW copies the original app.config file to my new project's folder, the changes that I make are done on my copy, not on the original one, so when i try to see the modifications i can't because the original file wasn't touched.

Any clue about this?

Thanks!!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)