Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

like image 231
HamedFathi Avatar asked Jul 31 '17 13:07

HamedFathi


1 Answers

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

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>

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

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>

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.

like image 137
Matt Ward Avatar answered Sep 16 '22 18:09

Matt Ward