Net包管理NuGet(4)打包nuget包的進階用法

 

nuget包不止能夠放進dll,還能夠引用其餘包,建立項目文件及替換配置文件html

  • 引用的時候同時引用依賴項假設引用某個dll須要依賴其餘的dll如Zeta.Core.dll須要引用ZETA.Serialization.Json.dll以下圖的包如何生成?

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

  2,c#

  

  

   (補充:上圖右邊點擊show all versions能夠選擇包的版本關聯,若有多個版本能夠選擇適合本身的版本)app

  

  最後點擊ok依賴關係就設置好了.dom

  • 源碼及文件夾

    引用包以後根據包的文件夾及文件建立以下圖項目目錄ide

    

    建立包的方法spa

    

    

    結果以下圖:debug

    

 (1)源碼文件須要替換命名空間的須要在文件後面加.pp3d

上圖源碼內有命名空間 每一個項目命名空間都有差別 要讓引用的包自動更換命名空間那就修改源碼文件命名空間替換代碼爲$rootnamespace$ 安裝以後就會被替換爲項目的命名空間,以下code

同理其餘文件若是須要動態的替換屬性打包時候必定要在文件後綴加上.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>

更多詳細內容可閱讀微軟官方文檔

相關文章
相關標籤/搜索