• Net包管理NuGet(4)打包nuget包的进阶用法


    nuget包不止可以放进dll,还可以引用其他包,创建项目文件及替换配置文件

    • 引用的时候同时引用依赖项假设引用某个dll需要依赖其他的dll如Zeta.Core.dll需要引用ZETA.Serialization.Json.dll如下图的包如何生成?

      1,参照第2步修改包的基础信息及基础的dllNet包管理NuGet(2)nuget包的生成方法

      2,

      

      

       (补充:上图右边点击show all versions可以选择包的版本关联,如有多个版本可以选择适合自己的版本)

      

      最后点击ok依赖关系就设置好了.

    • 源码及文件夹

        引用包之后根据包的文件夹及文件创建如下图项目目录

        

        创建包的方法

        

        

        结果如下图:

        

     (1)源码文件需要替换命名空间的需要在文件后面加.pp

    上图源码内有命名空间 每个项目命名空间都有差异 要让引用的包自动更换命名空间那就修改源码文件命名空间替换代码为$rootnamespace$ 安装之后就会被替换为项目的命名空间,如下

    同理其他文件如果需要动态的替换属性打包时候一定要在文件后缀加上.pp

     (2)webconfig内容替换及新增

    包的 content 文件夹中的 app.config.transform 和 web.config.transform 仅包含要合并到项目现有 app.config 和 web.config 文件中的元素。

    例如,假设项目最初在 web.config 中包含以下内容:

    <?xml version="1.0" encoding="utf-8"?>
    
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      https://go.microsoft.com/fwlink/?LinkId=169433
    -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
    
    <system.data>
        <DbProviderFactories>
          <remove invariant="MySql.Data.MySqlClient" />
          <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
        </DbProviderFactories>
      </system.data>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.6.0" newVersion="2.0.6.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="NPOI.OOXML" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.6.0" newVersion="2.0.6.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    若要在包安装期间将 MyNuModule 元素添加到 modules 部分,请在包的 content 文件夹中创建 web.config.transform 文件,如下所示:

    <configuration>
    <system.webServer>
        <handlers>
          <add name="st" verb="*" path="*.html" type="System.Web.StaticFileHandler"/>
        </handlers>
        <defaultDocument>
          <files>
            <add value="forms/login.html"/>
          </files>
        </defaultDocument>
      </system.webServer>
    </configuration>

    NuGet 安装包后,web.config 将显示为:

    <?xml version="1.0" encoding="utf-8"?>
    
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      https://go.microsoft.com/fwlink/?LinkId=169433
    -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
      </system.web>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
    
    <system.data>
        <DbProviderFactories>
          <remove invariant="MySql.Data.MySqlClient" />
          <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
        </DbProviderFactories>
      </system.data><system.webServer>
        <handlers>
          <add name="st" verb="*" path="*.html" type="System.Web.StaticFileHandler" />
        </handlers>
        <defaultDocument>
          <files>
            <add value="forms/login.html" />
          </files>
        </defaultDocument>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.6.0" newVersion="2.0.6.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="NPOI.OOXML" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.6.0" newVersion="2.0.6.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    更多详细内容可阅读微软官方文档

  • 相关阅读:
    OpenStack kolla 多 region 部署配置
    docker rpm 下载地址
    kolla-ansible 源码下载
    Linux下常用压缩 解压命令和压缩比率对比
    Python 获取秒级时间戳与毫秒级时间戳
    OVS 内核KEY值提取及匹配流表代码分析
    字符串压缩 牛客网 程序员面试金典 C++ Python
    奇偶位交换 牛客网 程序员面试金典 C++ Python
    寻找下一个结点 牛客网 程序员面试金典 C++ java Python
    平分的直线 牛客网 程序员面试金典 C++ Python
  • 原文地址:https://www.cnblogs.com/wuyubing/p/10456253.html
Copyright © 2020-2023  润新知