nuget包不止能够放进dll,还能够引用其余包,建立项目文件及替换配置文件html
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=\"Web\" /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=\"Web\" /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>
更多详细内容可阅读微软官方文档