如何在nuget中创建像Microsoft.AspNetCore.All这样的元软件包(所有软件包)?
New meta package – package of all packages – Microsoft.AspNetCore.All如何在nuget中创建像Microsoft.AspNetCore.All这样的元软件包(所有软件包)?
是什么Microsoft.AspNetCore.All代表什么?首先让我们回顾一下 针对ASP.NET Core的第一个版本。微软然后宣布 一切都将是一个(nuget)包。即使MVC本身也是一个nuget 包。如果你想MVC你可以通过nuget安装它。如果你想 启用CORS,你可以通过nuget安装它。类似于Node.js的东西012xx带有npm包。一切都是模块化的和点点滴滴。你到 选择你想要安装的东西。即使这是非常整洁它有 的缺点。安装所有需要的软件包,更新 它们,维护项目,删除未使用的软件包等等可能会很麻烦。而对于新手来说,可能会很令人厌恶地使用.NET或.NET Core。
如何在自己的库的nuget中创建像Microsoft.AspNetCore.All这样的meta包(所有包的包)?
元包是一个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>
注已被删除,因为所有的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将不会尝试安装任何依赖项,并且它会在早期产生错误。