In one of my c# application, i have to write directories path inside config file as following
Main Folder = Sites
Sub Folders = 400, 500, 600, and so on
For each subfolders = Inst, Prof
Inside Inst and Prof , we have multiple files.
Inside my program, i have to fetch all sites (400, 500 etc) and then i have to write loop for all sites for both folders (Inst and Prof) one by one, once DONE then go for next site and so on
What is best way to write above folder structure in App.config file?
You should check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.
Unraveling the mysteries of .NET 2.0 configuration
Decoding the mysteries of .NET 2.0 configuration
Cracking the mysteries of .NET 2.0 configuration
Highly recommended, well written and extremely helpful! This will give you a thorough understanding of the .NET configuration system.
To design your own custom section, there's also a handy tool (Visual Studio add-in) called Configuration Section Designer that will make it very easy and simple to create your own custom section and have it build up all the necessary code to handle that custom section.
There is an easy way to create custom configure . custom-configuration-sections-in-3-easy-steps
Related
Apologies if this has been asked before; after two days of searching I can only find partial answers that don't fully relate to my situation, and are difficult to follow with my lack of experience.
I have a solution that contains four projects:
Class library (containing database connection strings, email server settings, plus lots of other settings)
Web application (web forms)
Web application (MVC)
Web API
Projects 2,3 & 4 all reference the class library, and use the database connection strings, etc, to function. These projects also contain their own additional settings in web.config, bespoke to that project.
Everything works great so far... However, I now need to publish client-specific versions of my solution, e.g. the solution for ClientABC requires different settings for each project than for ClientXYZ. All other aspects remain the same, it is simply the config settings across the four projects that need to change.
From my research, I hit upon something called SlowCheetah which transforms the config files based on the publish profile. That sounded promising, but then I get this problem, where the class library settings aren't pushed into the other projects. I can see bits of useful info in this question, but don't have the experience to apply it to my problem. I'd rather not duplicate the settings into respective project's config file if possible, as that feels messy.
Can anyone please offer me some help as to what's best here? I don't even know if I'm taking the right approach, but am pretty sure I can't be the first ask this?
but then I get this problem, where the class library settings aren't pushed into the other projects
you have to keep in mind that the configuration file is readed by the SturtUp application, your client. Class Library can't run directly, but inside a WebApp or WinApp or ConsoleApp
So, any settings that you put in your ClassLibrary configuration file must be copied in the configuration file of your WebApp.
Generally, I copy some settings from app.config to web.config but, if you search on internet, you can find a method to automate this operation.
I now need to publish client-specific versions of my solution
You can create many configuration profile and use a web.config transformation:
From ToolBar or Build Menu, select Configurazion Manager...
Create all configuration you need for clients
Now you can see different web.configuration files
Now you can specify different configurazion transformation for your ClientABC, ClientXYZ and publish them with specific configuration
EDIT:
So, you can adopt this solution for your Class Library too, or external config file, and include external file in your web.config: External Config
I work on a team that works on a project. I change my project web config file to set a specific connection string but when I check-in or get latest version of project it changes to others connection strings. I have same problem in WCF Service references. appconfig and xsd files of service references always corrupted when I check-in or get latest version of program from tfs and I have to delete service references and add it again! How can I get rid of this?
We had the same issue on our project (with connection strings), and found a good solution: http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx
By adding a connections.config file for each developer with his own connection string, we just needed to say that this file must not be a part of Source Control. Then in the web.config connectionString section, you just refer to the connections.config file.
Just be aware that you need to either transform your web.config or add the connections.config when publishing the site.
I know you can do the same about the appSettings section in the web.config.
How you do it with WCF, I don't know - but it sounds strange to me that your are not using the same WCF refence.
There are many solutions.
The team uses the same configuration (e.g. everyone uses localhost references)
You separate user from application settings (do not apply to all kind of settings nor projects)
Use transforms and solution configuration to map have per-environment setting
Use configSource to move config section in separate files that are not under version control
I do not think there is a perfect solution, but maybe you apply a mix of these. I strongly suggest to apply them in the stated order.
I am using the Nuget Packager extension to create a Nuget Package to include my Logger project and Nlog. I have this working correctly but had a question about how do i use the correct config file for multiple environments (Dev/QA/Prod)?
Do I have multiple config files, one for each environment in the package? but how does the correct one get applied in QA for example, since different environments might have different listeners or targets? Whats the best way to accomplish this, an example to show how to do this would be great since i am new to Nuget and Nlog.Thanks for your help!
Nlog supports different locations of its config file. One of the location is the main configuration file of application. For more information please see Nlog documentation
Then we can use config transformations option. Visual studio supports this by default for web firendly projects (ASP.NET MVC, WCF etc.). If you application is of different type you can use an extension called SlowCheetah(NuGet Link). More information can be found at this page.
Config transformation deped on build configurations in visual studio. In web project you can see that web.config has two transformations: web.Debug.config and web.Release.config.
Hope it helps
I have recently upgraded to the newest Umbraco 4.11.1 and the old way to create custom sections doesn't seem to work any more. Which isn't a bad thing because that didn't really work well. However I can't seem to find any information at all on how to create one in the newer versions.
I found this blog post:
as from here on the entries for applications and application trees have now been moved to config files located in the config folder. Unsurprisingly, these are named applications.config and trees.config.
However I don't even have applications.config and trees.config.
And I can't find any other information about this.
Thank you,
Thomas
Because you upgraded the site, you probably didn't copy any files from the config folder. I'd suggest copying the applications.config and trees.config from the zip you downloaded for the upgrade.
If i use an external configuration file for Microsoft enterprise library for my program, then all the configuration for enterprise library must reside in the external configuration file? can i still have part of the configuration in the hosting configuration file?
If I understand you correctly you want to configure Entlib in an external file, and override some settings on your app.config?
If that's the case, check the EntLib Hands-On Labs. Particularly take a look at the configuration HOL; it shows you how to inherit configuration from a shared location, and override it.
I am using Enterprise Library 5.0
I needed to reference my enterprise library config outside the app.config.
I used the following with my own logging factory:
var configSource = new FileConfigurationSource("EntiLib.config");
var logWriterFactory = new LogWriterFactory(configSource);
var logWriter = logWriterFactory.Create();
I was able to find this solution on CodePlex
answer on code plex
Good links by Nicolas and Peter. Glad you found the hands-on labs useful. In addition, please take a look at this chapter that we wrote to explain various configuration scenarios, including:
reading configuration information from a wide range of sources.
enforcing common configuration settings across multiple applications.
sharing configuration settings between applications.
specifying a core set of configuration settings that applications can inherit.
merging configuration settings that are stored in a shared location.
creating different configurations for different deployment environments.