c# - 转换 NuGet 包类库项目的文件

标签 c# visual-studio-2015 nuget

我使用 Visual Studio 2015 创建了一个类型为“类库(包)”的项目。

我应该如何将网络/应用程序配置转换文件添加到 NuGet 包?

最佳答案

将文件添加到您的项目中,名为:App.config.install.xdt

在您的 .nuspec 文件中添加:

<files>
    <file src="App.config.install.xdt" target="content\App.config.install.xdt" />
</files>

https://msdn.microsoft.com/en-us/library/dd465326.aspx

以下示例显示了更改连接字符串并替换 customErrors 元素的转换文件的内容

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="MyDB" 
      connectionString="value for the deployed Web.config file" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <customErrors defaultRedirect="GenericError.htm"
      mode="RemoteOnly" xdt:Transform="Replace">
      <error statusCode="500" redirect="InternalError.htm"/>
    </customErrors>
  </system.web>
</configuration>

注意“.transform”文件,如果你想添加一个不叫 app.config 的文件。

关于c# - 转换 NuGet 包类库项目的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34948093/

相关文章:

unity3d - 使用 unity Visual Studio 编写统一着色器

c# - OOP 最佳实践 : Employee. GetCars() 与 Cars.GetByEmployee()

c# - Windows Mobile 中的 Flash SMS

visual-studio-2013 - .net WP8.1/Win10 UWP : Namespace for MapControl not found in Visual Studio Designer

nuget - 使用用户凭据进行 dotnet nuget 推送

c++ - 为通过 Nuget 安装的 C++ 库设置链接类型

.net - 更新同版本号的Nuget包

c# - 检查身份验证票过期而不影响它

c# - 创建txt文件无法访问其他进程正在使用的文件

c - 即使分配了大堆栈大小,如何消除堆栈溢出错误?