Which appSetting.config file is my project using - c#

I am very new to C# and I have read several posts about using configuration files. I have perhaps a very basic question I have been unable to find an answer to. I created a Config folder inside my project to put some path information for input/output files. There also seems to be a Config folder inside the \bin\debug\folder. My App.config file points to Config\appSettings.config. I can't figure out which Config folder is getting used in my project. Is it the Config folder I created or is it the Config folder inside the \bin\debug\ folder? Thanks in advance for any help and I hope I followed all the rules for posting a question.

I think that it's potentially both files.
Whenever you build your application, the compiled .exe, .dll and .config files are copied or written to the \bin\debug folder. The application is then run from the \bin\debug folder. The App.config file in your project directory gets automatically transformed into a file called ProjectName.exe.config which is what the ConfigurationManager class looks for.
If you use configSource in your App.config file to reference another configuration file such as Config\appSettings.config then this will also need to be copied to your \bin\debug folder so that it can be can be accessed when your program is run.

Related

I want to keep .dll specific config file outside the project folder (C#)

I want to keep my Project.dll.config file in local drive (Outside the project folder), I'm setting config file path this way. but I'm not getting how to read the config file. AppDomain.CurrentDomain.SetData ("APP_CONFIG_FILE", "H:\Test\")

Visual Studio: different project folder structure for publishing/editing than the physical one

I'd like to add files to a web csproj that are located under its directory, but in a different directory structure than the physical one. Example physical directory structure:
MyProject.csproj
Assets
Settings.config
Now my project needs the following structure when I publish the project (i.e. on the server when deployed) and would be nice if this structure would be visible from Visual Studio too:
MyProject.csproj
Config
Settings.config
Notice that Settings.config isn't in the Assets but in the Config folder.
I don't want to copy the files over, I can't move them and I can't change where these files are loaded from.
Is it possible for such files to be located in the Assets folder while
from VS they appear to be in the Config folder,
and when the project is published they are copied to the Config folder.
The latter one is possible with post-build tasks I think and I believe I can implement it. However I'd like to have the whole development experience, including the folder structure in VS, to show the file being under Config. Is this possible?
I'm looking for something like solution folders, but for projects. Adding files as links would work great, but since the files are in the physical folder of the project I get the error "Cannot add a link to a file that is inside the project tree".

Visual C# missing app.config file after build

My solution has two exe apps inside. Console application (Console.exe) and wpf application (MyUI.exe). Wpf application is a startup project, and console one is a small installation tool. Both have app.config file which contains db info. I have problem with this config file after I build the solution. In bin folder I have my wpf app and config file with the same name, e.g.:
MyUI.exe and MyUI.exe.config.
But there is no config file for console application. Is there any setting I should set to make it right?
When I set build action to content and copy to output... to Copy always then I have "App.config" file in bin directory, but there is no "Console.exe.config".
There is no such thing as a solution output folder - each project has it's own output folder, in which the App.config will be placed (after it's renamed to [exe_name].config).

Change file name <AssemblyName.exe.config> to <App.Config> for output directory in Visual Studio

I have a C# project and an App.Config file in this project. When i build the source code, a file (AssemblyName.exe.config) is created in the output directory for the application configuration but i want the name of this file App.Config. How can i do that?
but i want the name of this file App.Config.
You can use a post-build event to rename the file.
However, realize that the application settings architecture which uses the file will expect the name to be AssemblyName.exe.config. If you rename the file, the normal application settings architecture will break.
You access in your Application Build, in Event Post Build add action who rename file.
rename "YourPath/AssemblyName.exe.config" "YourPath/App.Config"

c#: config file in bin\debug folder

I kept getting errors in my log file that messageconfig file not found. It turned out that my application was expecting it in the bin\debug folder. What causes the application to expect so? It seems that when project is built it should copy the config file in bin\debug folder. Am i missing a certain project setting?
App/web.Config files are expected to be in the same directory as the application/web root.
Other, referenced config files may be in other directories, as specified in the main configuration file.
If you right click on the .config file, then on properties there is a Copy to Ouput Directory entry.
This should be set to either Copy if Newer or Copy always, if this is set to Do not copy, the .config will not by copied to the debug/release folder where it is expected.
Config files are expected to be in the same location as the executing assembly.
Check out this SO question:
.NET 2.0 Application Settings (user.config) file location
You could set the files build action to "Copy always"..
usually you only need the .exe. Try to clean and rebuild your project..
Hope it helps

Categories

Resources