【问题标题】:Visual Studio 2015 - Change Setting or Variable at time of PublishVisual Studio 2015 - 发布时更改设置或变量
【发布时间】:2016-06-23 13:48:47
【问题描述】:

应用发布时是否可以更改设置或变量

或者是否有某种条件可以运行 IF THEN?

例如,我想在发布时更改日志文件的写入方式,而我在发布时经常忘记进行更改

【问题讨论】:

  • 您是否考虑过使用发布配置文件?
  • 我已经阅读了一些关于它们的信息,如果可以的话,我会更深入地挖掘
  • 它们非常适合拥有多个发布环境。在下面的答案中,我将向您介绍我们如何使用发布配置文件来更改变量
  • 谢谢,我马上试试
  • @mrreinsmith 进展如何?

标签: variables visual-studio-2015 clickonce publish application-settings


【解决方案1】:

Web.Live.Config:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
    finds an attribute "name" that has a value of "MyDB".
 -->
  <appSettings>
    <add key="ClaimPackPath" value="C:\\inetpub\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>

Wg.Debug.Config:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
    finds an attribute "name" that has a value of "MyDB".
 -->
  <appSettings>
    <add key="ClaimPackPath" value="C:\\Debug\\wwwroot\\Application\\ClaimPacks\\" xdt:Locator="Match(key)" xdt:Transform="Replace" />
</appSettings>
</configuration>

然后在应用程序中,您可以像这样请求变量:

string filepath = ConfigurationManager.AppSettings["ClaimPackPath"];

它会随着您在发布时选择的任何发布配置文件而改变:)

【讨论】:

    猜你喜欢
    • 2018-03-17
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多