I have a question about recompiling different components of C# console app after making changes
Program.cs --> needs to be rebuilt to see changes
App.config --Not sure
Also i have a folder called UserFiles which has a csv file that I refer in my Program.cs file. If I make changes to either App.config or csv file should I recompile the program. Can someone explain to me how this works please?
Thanks
R
Correct
The App.config file is essentially just a XML file that your program can read settings from when it runs. You don't need to recompile if you make changes to that.
No. Your CSV has absolutely nothing to do with the compilation of your program
Related
I am currently having an issue with removing the app.config file from my project.
I wish to have a single .exe file, however, every time I delete the app.config the program will not run.
Does anyone know of a solution to prevent the application from trying to find a app.config file?
Thanks
In several C# projects I have been using an app.config file to pass various settings to my program, settings like connectionstrings, power levels etc.
However sometimes I have come in situations where the settings aren't updated as expected and I have concluded that I am not that well informed with the proper use of app.config file.
Example:
Replacing the .exe file with a new version (where settings are different) to the output directory without changing the exe.config, results in the program seeing the hard-coded settings and not the settings of the existing .exe.config
So my Questions are:
What is the exact role of exe.manifest file
Every time I create a new .exe do I have to paste in the output folder anything else except the .exe file?
Whats the difference in obtaining the setting value by: ConfigurationManager.'settingName'... rather than:
Properties.Settings.Default.'settingName'?
What is the role of app.config build action?
Sorry If I am asking too much in a single Question.
The app.config file is a file that gets a special treatment when running the associated application. If you executable is named MyApp.exe the app.config file should be named MyApp.exe.config. The role of the app.config build task is to copy the file named app.config in your project to MyApp.exe.config in the output directory.
.NET provides ways to read the contents of the file (it is in XML format) and various parts of .NET will look for different sections in this XML to provide configuration.
A widely used section is the settings section you refer to as Properties.Settings.Default. This section plays together with Visual Studio that provides an editor for application settings. The settings are accessed in the code by using a generated class. Adding a setting will add a property to this class and this property is initialized from a value in the app.config file.
In the Visual Studio editor you can set a value for the setting and you can think of this as a default value for the setting. However, if you overwrite the value in the app.config file the later will take precedence. This allows you to modify the app.config file after installation and rerun the application with a modified setting.
You can also access application settings the app.config file using other methods, but in my oppinion using the Visual Studio editor and the code generated class is the best way to do that.
I am not sure I fully understand the problem that you experience. If you update MyApp.exe and leave MyApp.exe.config intact you should not see a change in the settings used by the application (unless of course you have renamed or changed some settings).
The manifest file provides information about side-by-side assemblies and can be used to request elevated privileges among other things. This is not related to the app.config file.
There quite a few resources about that.
See http://msdn.microsoft.com/en-us/library/ms229689%28v=vs.90%29.aspx
and the (better) overview: http://msdn.microsoft.com/en-us/library/k4s6c3a0%28v=vs.110%29.aspx
app.config is a very powerful tool. It addresses many issue like versioning, migration, upgrading etc. but this requires some in-depth reading from the links above.
Maybe one thing you could do, if you want to copy only .exe file every time you build your app, is make a settings.ini or settings.txt file, put your parameters in this file (that are not secret of course) and read all your settings from there when you start your app.
You can put all your connection string logic in your login form if you have one...
I write a small application, that I don't need store anything in config files. So the file App.config in my source is exactly what ever Visual Studio has created.
So I want to delete this file from source code (before compiling). But I noticed that it also contains the .NET version information. I wonder if I delete App.config file, then copy my application to other pc, is it have any strange behavior?
I wonder if I delete App.config file, then copy my application to other pc, is it have any strange behavior?
Nope, it should be fine. There are various (somewhat tortuous) rules about exactly what version of the CLR etc gets used in what situations, but for the most part you're fine to just rely on the default behaviour.
You really don't need an app.config file unless you need to give specific settings.
I am making one windows application in c# in where i added one file as app.config file.I have written some code in that file as
<appSettings>
<add key ="FlagForArchiving" value="true"/>
</appSettings>
In 'program.cs' file i am reading this value as
ConfigurationSettings.AppSettings["FlagForArchiving"].ToString();
On local machine i can retrieve value from config file but whenever i am building that application and running on any other machine then I cant read the value from config file.I am trying to run my application on windows 7.Please help me.Thanks in advance.
app.config is renamed to <MyProgramName>.exe.config when you build. When your program runs it will look for that <MyProgramName>.exe.config file, not app.config.
You need to deploy the renamed file (<MyProgramName>.exe.config) along with your program.
In your case, you need to copy over OBViewer.exe, OBViewer.exe.config, and any other files that OBViewer.exe depends on (e.g. other .dll assemblies in your debug/release directory).
By the way, this renamed file is often commonly referred to as "app.config", even if it doesn't have the same filename.
and the app.config file exists on the other machine?
Before reading check if it exists
The exception you get says whats incorrect: "FileNotFoundException"
EDIT
here is the correct way!
if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
MessageBox.Show(ConfigurationSettings.AppSettings["FlagForArchiving"].ToString());
}
I have a class library, which has an app.config and when built it put the app.config along with the dll in the output directory I have chosen.
I don't want it to be name app.config though, if I have another component that has it's own dll, I can see confusion happening.
I've been looking at another project, that does exactly that, but I can't see why it outputs dllname.dll.config and mine always app.config.
Any ideas?
Thx
You probably have set the Copy to output directory setting of the app.config.
BUT: In a class library, an app.config is useless.
Note, that you can only have one config file per application. The configuration is being read (at execution time) from <executing assembly file name> + ".config".