35

Windows Server を作成しようとしています。私はC#でいくつかのロジックを持っています

        string urlToPing = ConfigurationSettings.AppSettings["UrlToPing"].ToString();
        Stream data = client.OpenRead(urlToPing);

私は読む必要があります

ここに私のApp.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="UrlToPing" value="http://mysite.com"/>
  </appSettings>

</configuration>

私は Windows サービスの初心者です。私の質問は次のとおりです。

  • サービスのフォルダーに公開するとき、またはビルドを作成するときに App.Config ファイルが表示されない
    • ConfigurationSettings.AppSettings に関する Visual Studio の警告が廃止されました (代わりに何を使用すればよいですか?)
4

2 に答える 2

4

最初の質問に対して、実行可能プロジェクト (Windows サービス、コンソール アプリケーションなど) をビルドすると、app.config の名前が "YourApplication".exe.config に変更されます。ここで、"YourApplication" はスタートアップ アセンブリの名前です。次に、ファイルを出力フォルダーにコピーします。

于 2013-04-15T09:17:50.410 に答える