【问题标题】:How do I apply xdt transforms on app.config on installing/updating nuget package?如何在 app.config 上应用 xdt 转换以安装/更新 nuget 包?
【发布时间】:2015-12-05 20:25:54
【问题描述】:

我最近更新了我的一个 nuget 包,因此它现在需要在使用项目中存在应用设置。我想将 app.config 转换添加到包中,以便任何使用我的包的新版本的人都将使用一些默认值填充此应用程序设置。为此,我按照this post 创建了 app.config.install.xdt 文件。

   <?xml version="1.0"?>
   <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
       <appSettings xdt:Transform="InsertIfMissing">        
          <add key="CustomSetting" value="CustomValue" />
       </appSettings>
    </configuration>

我还根据this stackoverflow post在我的nuspec中添加了一行

     <file src="\Content\app.config.install.xdt" target="app.config" />

但是,当我在消费者中安装/更新此软件包时,我没有看到此应用设置显示在消费者的 app.config 中。我还缺少其他步骤吗?

【问题讨论】:

  • 您还应该将 xdt:Transform="InsertIfMissing" 添加到您的 条目中。否则,当您更新软件包时,密钥将再次插入。

标签: c# asp.net nuget app-config xdt-transform


【解决方案1】:

nuspec 文件条目看起来不正确。它应该是这样的:

 <file src="Content\app.config.install.xdt" target="content" />

您的目标是不正确的 app.config。 .xdt 转换需要位于 NuGet 包内的内容目录中。

【讨论】:

  • 你是什么意思 - “.xdt 转换需要在 NuGet 包内的内容目录中”?你的意思是说,过程是创建nupkg文件,然后打开修改?还是您的意思是在 VS 项目中创建一个名为“content”的文件夹并将 .xdt 文件放在那里?
  • 表示NuGet包(.nupkg)内应该有内容目录。您无需打开和修改 .nupkg 文件,您可以使用 nuget pack 命令生成它。您无需在 Visual Studio 项目中创建文件夹。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
相关资源
最近更新 更多