我创建Windows服务和服务的安装项目。 在我的Windows服务中,我可以得到我的客户操作数据认为是这样的:
Context.Parameters["dbname"]
但是我想在我的服务中访问我的客户操作数据的值,以便在我的项目中使用它。
有人知道如何在c#中做到这一点吗?
更新
在我的ProjectInstaller中:
public ProjectInstaller()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string dbName = Context.Parameters["dbname"];
AppHelper.Save(dbName+" "+ Context.Parameters["targetdir"].ToString());
string xml = Context.Parameters["targetdir"].ToString() + "App.config";
XmlDocument document = new XmlDocument();
document.Load(xml);
XPathNavigator navigator = document.CreateNavigator();
XmlNamespaceManager ns = new XmlNamespaceManager(navigator.Nametable);
foreach (XPathNavigator nav in navigator.Select(@"/configuration.appSettings/add[@key='dbName']"))
{
nav.Setvalue(dbName);
}
document.Save(xml);
}
我的Windows服务的 app.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="dbName" value="totodb"/>
</appSettings>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
当我尝试安装项目时,出现一个错误,提示我 app.config 不存在。