c# - 如何在安装/更新 nuget 包时对 app.config 应用 xdt 转换?

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

我最近更新了我的一个 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 添加了一行 my nuspec

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

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

最佳答案

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

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

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

关于c# - 如何在安装/更新 nuget 包时对 app.config 应用 xdt 转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32486813/

相关文章:

c# - 为什么GetManifestResourceStream调用GetManifestResourceNames时资源名存在却返回null?

azure - 无法在 Windows Phone 8 应用程序中安装 Windows Azure SDK

C# 应用程序在检索 youtube 请求时卡住

c# - 为什么这些随机事件遵循特定的模式?

c# - html.raw 未呈现

c# - 有关在 ASP.NET 应用程序中缓存的最佳实践

Javascript 错误 : unable to get value, 即使它不为空

versioning - NuGet 如何决定是否使用本地包缓存?

c++-cli - 为 C++/CLI(混合)程序集创建 NuGet 包

c# - 透明代理 - 从端口 80 到 443