visual studio 2010 - c#用于部署如何将库项目的设置添加到主可执行项目

本文关键字:项目 设置 添加 可执行 2010 studio 用于 部署 visual | 更新日期: 2023-09-27 17:49:42

我在Visual Studio 2010中工作,在那里我有一个主项目和两个其他库项目,并且在主项目中添加了参考。每个项目都有一个设置文件。构建解决方案后,主项目只有一个.config文件,但库项目没有.config文件。因此,我无法在外部更改这些库项目的设置。

那么这个问题的解决方案是什么,我可以把库项目的.config文件放入我的调试/发布文件夹?

app.config

<?xml version="1.0"?>
<configuration>
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="Communicator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="DatabaseManager.Database.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
</configSections>
<applicationSettings>
    <Communicator.Properties.Settings>
        <setting name="ApplicationConfigsDirectory" serializeAs="String">
            <value>'Application_Configs</value>
        </setting>
        <setting name="MaxMeterConn" serializeAs="String">
            <value>10000</value>
        </setting>
        <setting name="MaxPhyConn" serializeAs="String">
            <value>20000</value>
        </setting>
        <setting name="ServerIP" serializeAs="String">
            <value>0.0.0.0</value>
        </setting>
        <setting name="Port" serializeAs="String">
            <value>1114</value>
        </setting>
        <setting name="TCPTimeOut" serializeAs="String">
            <value>3900000000</value>
        </setting>
        <setting name="isTCPTimeOut" serializeAs="String">
            <value>True</value>
        </setting>
        <setting name="SchedulerPoolingTime" serializeAs="String">
            <value>480000</value>
        </setting>
        <setting name="startKAScheduler" serializeAs="String">
            <value>True</value>
        </setting>
        <setting name="MinCacheAge" serializeAs="String">
            <value>00:02:00</value>
        </setting>
        <setting name="MaxCahceAge" serializeAs="String">
            <value>00:05:00</value>
        </setting>
        <setting name="SaveLogToDBFlag" serializeAs="String">
            <value>True</value>
        </setting>
        <setting name="Instance" serializeAs="String">
            <value>MDC_Tester</value>
        </setting>
    </Communicator.Properties.Settings>
    <DatabaseManager.Database.Properties.Settings>
      <Setting Name="Server" Type="System.String" Scope="Application">
        <Value Profile="(Default)">192.168.30.181</Value>
      </Setting>
      <Setting Name="Database" Type="System.String" Scope="Application">
        <Value Profile="(Default)">tester</Value>
      </Setting>
      <Setting Name="UserID" Type="System.String" Scope="Application">
        <Value Profile="(Default)">root</Value>
      </Setting>
      <Setting Name="pswd" Type="System.String" Scope="Application">
        <Value Profile="(Default)">nothing</Value>
      </Setting>
      <Setting Name="MaxPoolSize" Type="System.Int32" Scope="Application">
        <Value Profile="(Default)">512</Value>
      </Setting>
    </DatabaseManager.Database.Properties.Settings>
</applicationSettings>
<system.runtime.caching>
<memoryCache>
  <namedCaches>
    <add name="default"
         cacheMemoryLimitMegabytes="1024"
         pollingInterval="00:01:30" />
  </namedCaches>
</memoryCache>
</system.runtime.caching>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>

visual studio 2010 - c#用于部署如何将库项目的设置添加到主可执行项目

这是设置和配置文件的预期行为。您需要将库项目中的配置部分复制到主项目中。您还需要将相应的节元素添加到applicationSettings节组:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="SomeLibrary.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <section name="MainProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
</configSections>

然后在主配置中:

<applicationSettings>
     <SomeLibrary.Properties.Settings>
         <setting name="SomeSetting" serializeAs="String">
            <value>Whatever</value>
         </setting>
     </SomeLibrary.Properties.Settings>
     <MainProject.Properties.Settings>
        <setting name="MainSetting" serializeAs="String">
            <value>Yada yada</value>
        </setting>
    </MainProject.Properties.Settings>
</applicationSettings>

在上面的例子中,"SomeLibrary"设置类型是在主项目中声明的,然后与库相关的设置在主配置文件中与主项目的设置一起设置。