I\'m creating a console app in Visual Studio 2010 with c#. I want this app to be stand alone, in that all you need is the exe, and you can run it from anywhere. I also want
IL Merge has lot issue with wpf executable also slow. I ended up using Cosura.Fody https://github.com/Fody/Costura and using command line parameter for passing my app config value. Also using iexpress http://en.wikipedia.org/wiki/IExpress to create final executable with command line args and exe merged together
As others have pointed out, the idea behind a configuration file is to avoid hard-coded values.
What you might do as an alternative is to to write a custom configuration section, with every element optional and with default values. That way anyone who can get by with the defaults doesn't need a config file. But if they need to override a default, they can provide one.
(Sorry, just a bit of brainstorming. I don't have an example available.)
Take a winform application for example, during compilation, a file 'xxx.EXE.config' will be generated along with the output EXE file. It will contain the 'app.config' settings. Distribute this as well.
Best workaround looks like to create it yourself at the application startup.
Example code:
Program.cs
[STAThread]
static void Main()
{
CreateConfigIfNotExists();
}
private static void CreateConfigIfNotExists()
{
string configFile = string.Format("{0}.config", Application.ExecutablePath);
if (!File.Exists(configFile))
{
File.WriteAllText(configFile, Resources.App_Config);
}
}
Remember that it will only write your current config when building. It will not update it automatically when you deploy a new version. It will include the config as is when building. But this could be enough :)