I need to create an address string in app.config as:
<client>
<endpoint address="http://ServerName/xxx/yyy.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientIInfoService"
contract="DocuHealthLinkSvcRef.IClientIInfoService" name="BasicHttpBinding_IClientIInfoService" />
</client>
The ServerName
need to be entered by the user during installation.
For that i have created a new UI dialog in the Installer. I have also written an Installer.cs
class and overrided the install ()
as:
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDirectory = Context.Parameters["targetdir"];
string ServerName = Context.Parameters["ServerName"];
System.Diagnostics.Debugger.Break();
string exePath = string.Format("{0}myapp.exe", targetDirectory);
Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
config.AppSettings.Settings["ServerName"].Value = ServerName;
config.Save();
}
}
But how do i use this ServerName
in my app.config
to create the specified string.
I'm working on VS2010.
Assuming you are using the full ServiceModel section group in the app.config
Essentially you follow these steps:
Save config
You could use WiX (Windows Installer XML toolset) to build your MSI, in which case you can use the XmlFile utility tag to update the server name:
You can capture the server name during installation using a WixUI extension form.
Advantages of WiX: WiX is msbuild compliant (unlike .vdproj files), and gives you much finer-grained control over your installer, among other things
At the end of the day,
app.config
isxml
file. You can use Linq To XML or XPathNavigator to replace theaddress
attribute ofendpoint
element.Below code uses Linq to Xml
Since you have a windows-installer tag, I assume you either have an MSI package, or can create one...
Then:
A silent installation will be possible using:
try to use below two lines before saving the config file changes:
P.S: it doesn't update the solution item 'app.config', but the '.exe.config' one in the bin/ folder if you run it with F5.