如何在nuget中创建像Microsoft.AspNetCore.All这样的元包(所有包的包)? [英] How to create meta package (package of all packages) like Microsoft.AspNetCore.All in nuget?

查看:40
本文介绍了如何在nuget中创建像Microsoft.AspNetCore.All这样的元包(所有包的包)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新元包 – 所有包的包 – Microsoft.AspNetCore.All

Microsoft.AspNetCore.All 代表什么?首先让我们回顾一下ASP.NET Core 的第一个版本.微软随后宣布一切都将是一个(nuget)包.甚至 MVC 本身也是一个 nuget包裹.如果你想要 MVC,你可以通过 nuget 安装它.如果你想启用 CORS,您可以通过 nuget 安装它.像 Node.js 这样的东西使用它的 npm 包.一切都是模块化的.你可以选择您要安装的内容.即使它非常整洁,它也有它的缺点.安装所有需要的包,更新可能很麻烦他们,维护项目,删除未使用的项目等.对于新来者.NET 或 .NET Core 可能会令人反感.

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 这样的元包(所有包的包)?

How to create meta package (package of all packages) like Microsoft.AspNetCore.All in nuget for own libraries?

推荐答案

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

A meta package is a NuGet package that references other NuGet packages and typically does not include any assemblies itself.

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

If you create a .nuspec file, below is part of the Microsoft.AspNetCore.All NuGet package's .nuspec file, then define your dependencies, you can then call nuget pack YourNuSpecFile.nuspec to create your meta package.

<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>

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

Note in the above some of the dependencies have been removed since the All NuGet package depends on a lot of NuGet packages.

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

The NuGet package dependencies are defined in the dependencies section and you choose the minimum version you want to depend on. Also note that the above meta package has the dependencies inside a group which restricts the target frameworks supported by the NuGet package. Another example below is the Xamarin.GooglePlayServices NuGet package. The .nuspec here does not specify a group and target framework for the dependencies.

<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 将不会尝试安装任何依赖项,并且会在早期产生错误.

If your NuGet packages support not many target frameworks then it is probably better to specify the group and target framework. Then NuGet will not attempt to install any of the dependencies if the project is not supported and it will produce an error earlier on.

这篇关于如何在nuget中创建像Microsoft.AspNetCore.All这样的元包(所有包的包)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆