Reputation: 1857
I have a .net solution having a reference hierarchy like this MyWinApp->ServerCore->DataAccess where the last two are class libraries and myWinApp is a windows app.
Now, each time I want to run this project on different servers I need to rebuild the project since I couldn't manage to separate the configuration file(app.config) of DataAccess project that has connection string related configurations.
How can I separate database configurations from the application code? I tried to build action options but it doesn't work :S What might be the most feasible solution?
Thanks in advance
Upvotes: 0
Views: 369
Reputation: 404
I think you can use applicationSettings to include configuration for specific referenced assemblies:
For example:
<configuration>
<applicationSettings>
<ProjectName.Properties.Settings>
<setting name="ConnectionString" serializeAs="String">
<value>YourConnectionStringHere</value>
</setting>
</ProjectName.Properties.Settings>
</applicationSettings>
</configuration>
Where "ProjectName" is the name of the reference you need to configure. Each project can have it's own app.config with the above applicationSettings entry and a value specific to the project itself.
Upvotes: 0
Reputation: 2975
The configuration should most likely go with the MyWinApp project. The configuration file goes with what is executing. So if you make an installer for your application, it'll have a configuration file called MyWinApp.exe.config that was created from your App.Config.
Basically the app.config with your Datalayer.dll doesn't really do much.
What you might want to do is look at how the configSource property works for configuration files in .net here: http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx and see if this is what you're looking for. This lets you set a configSource for your connection strings that you can change per machine.
All I do is setup a simple xcopy before a deploy and I have the correct configuration settings before deploying an asp.net app. If you have to package an installer, copying the correct files before building the installer should do the trick as well.
Upvotes: 2
Reputation: 3371
For my DAL projects I typically have a DataLayer.dll.config file but I actually add the ConnectionString entries to my Program.exe.config file. I don't know that you need anything special for this. Possibly just reference a static readonly string or something from the DataLayer.dll in the Program.exe?
Or, do you really want to have separate configuration files? If so then you can use the ConfigurationManager class to open a loose configuration file with the OpenMappedMachineConfiguration method. See MSDN ref here: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedmachineconfiguration.aspx
Upvotes: 1