加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何在nuget中创建像Microsoft.AspNetCore.All这样的元包(所有包

发布时间:2020-12-14 01:57:39 所属栏目:Windows 来源:网络整理
导读:New meta package – package of all packages – Microsoft.AspNetCore.All What does Microsoft.AspNetCore.All represent? First lets look back at first release for ASP.NET Core. Microsoft then announced that everything would be a (nuget) packa
New meta package – package of all packages – Microsoft.AspNetCore.All

What does Microsoft.AspNetCore.All represent? First lets look back at
first release for ASP.NET Core. Microsoft then announced that
everything would be a (nuget) package. Even the MVC itself is a nuget
package. If you want MVC you can install it via nuget. If you want to
enable CORS you go install it via nuget. Something like Node.js does
with its npm packages. Everything is modular and in bits. You get to
choose what you want to install. Even tho that is very neat it has its
downsides. It can be hassle to install all the needed packages,update
them,maintain project,remove unused ones etc. And for newcomers to
.NET or .NET Core it can be quite repulsive.

如何在nuget中为自己的库创建元数据包(所有包的包),如Microsoft.AspNetCore.All?

解决方法

元包是一个引用其他NuGet包的NuGet包,通常不包含任何程序集本身.

如果您创建.nuspec文件,下面是Microsoft.AspNetCore.All NuGet包的.nuspec文件的一部分,然后定义您的依赖项,您可以调用nuget pack YourNuSpecFile.nuspec来创建您的元包.

<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>Microsoft.AspNetCore.All</id>
    <version>2.0.0-preview2-final</version>
    <authors>Microsoft</authors>
    <owners>Microsoft</owners>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <licenseUrl>https://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
    <projectUrl>https://www.asp.net/</projectUrl>
    <iconUrl>https://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
    <description>Microsoft.AspNetCore.All</description>
    <copyright>Copyright ? Microsoft Corporation</copyright>
    <tags>aspnetcore</tags>
    <dependencies>
      <group targetFramework=".NETCoreApp2.0">
        <dependency id="Microsoft.AspNetCore" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Diagnostics" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Hosting" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Routing" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Server.IISIntegration" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Server.Kestrel" version="2.0.0-preview2-final" />
        <dependency id="Microsoft.AspNetCore.Server.Kestrel.Https" version="2.0.0-preview2-final" />
      </group>
    </dependencies>
  </metadata>
</package>

请注意,上面的一些依赖项已被删除,因为All NuGet包依赖于很多NuGet包.

NuGet包依赖项在依赖项部分中定义,您可以选择要依赖的最低版本.另请注意,上面的元包在组内部具有依赖关系,这限制了NuGet包支持的目标框架.下面的另一个例子是Xamarin.GooglePlayServices NuGet包.这里的.nuspec没有为依赖项指定组和目标框架.

<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>Xamarin.GooglePlayServices</id>
    <version>18.0.0</version>
    <title>Xamarin Google Play Services Binding (ICS)</title>
    <authors>Xamarin Inc.</authors>
    <owners>Xamarin Inc.</owners>
    <licenseUrl>http://components.xamarin.com/license/googleplayservices</licenseUrl>
    <projectUrl>http://components.xamarin.com/view/googleplayservices</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>C# bindings for google play services.</description>
    <copyright>Copyright 2013-2014</copyright>
    <dependencies>
      <dependency id="Xamarin.Android.Support.v4" version="20.0.0" />
      <dependency id="Xamarin.Android.Support.v7.MediaRouter" version="20.0.0" />
      <dependency id="Xamarin.Android.Support.v7.AppCompat" version="20.0.0" />
    </dependencies>
  </metadata>
</package>

如果您的NuGet包支持的目标框架不多,那么最好指定组和目标框架.然后,如果不支持该项目,NuGet将不会尝试安装任何依赖项,并且它将在之前产生错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读