Skip to content

Instantly share code, notes, and snippets.

@ericstj
Created July 6, 2016 16:16
Show Gist options
  • Save ericstj/2efb0731a0538839d7c0c23bdef5cec9 to your computer and use it in GitHub Desktop.
Save ericstj/2efb0731a0538839d7c0c23bdef5cec9 to your computer and use it in GitHub Desktop.
How to resolve binaries from NuGet packages

Resolving binaries from NuGet packages

NuGet is handy for sharing code but sometimes you need to deal with raw binaries. Picking those directly out of NuGet packages can be challenging since NuGet has many complex/inter-related conventions for determining which assets are applicable.

This document will describe a technique for resolving binaries using NuGet's asset selection algorithm via DotNET CLI.

Prerequisites

  1. DotNET CLI, available here: https://www.microsoft.com/net/core

Steps

  1. Create a project by running dotnet new.
  2. Modify the project.json to include all of the packages you wish to resolve.
  3. Add "preserveCompilationContext": true under buildOptions
  4. Modify the frameworks and (optionally) runtimes section to control what assets are resolved from the packages.
  5. Run dotnet publish
  6. Runtime assets (aka implementation assemblies) will be in the published output directory. If these are not needed they can be ignored.
  7. Compile-time assets (aka reference assemblies) will be in a refs subdirectory of the published output.

Sample

This sample demonstrates how to resolve all of the reference assemblies for different frameworks that shipped at .NET Core 1.0 RTM.

The project can be found here: https://gist.github.com/ericstj/b274bf0700feb12d16d2f1fd4eb34cbe

To build the set of packages referenced by this project.json one can use the text files published to https://github.com/dotnet/versions/tree/master/build-info/dotnet to determine all packages produced by the .NET team. For example, the following represent the set of library packages shipped by the CoreFx repo at 1.0 RTM. https://github.com/dotnet/versions/blob/master/build-info/dotnet/corefx/release/1.0.0/Latest_Packages.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment