简体   繁体   中英

Embed vs reference my dependencies: Best practices for .NET/NuGet package?

I'm providing a C#/.NET class library to clients within my company as a NuGet package. My library depends upon some other 3rd-party libraries (eg Newtonsoft's excellent Json.NET ).

I'm assuming that the standard way NuGet works is that my package would only include references to other NuGet packages I depend upon. The client's Developer Studio will automatically download them when they install my NuGet package in their project.

Question #1:

Can I be certain that Developer Studio will download the versions of those NuGet packages that I was building against and not the 'latest' versions?

Question #2:

Will it cause problems if their project also uses a 3rd-party library that I'm using (like Json.NET), especially if they are using a different version? Does this 'just work', or do I need to do something about this?

Apologies if this is spelled out somewhere, but I've not been able to find specific answers to these questions.

That's clearly laid out in the Nuspec Reference

Specifically:

Specifying Dependencies

Starting from version 2.0, package dependencies can be specified to vary according to the framework profile of the target project. The element contains a set of elements. Each group contains zero or more element and a target framework attribute. All dependencies inside a group are installed together if the target framework is compatible with the project's framework profile.

  <dependencies> <group> <dependency id="RouteMagic" version="1.1.0" /> </group> <group targetFramework="net40"> <dependency id="jQuery" /> <dependency id="WebActivator" /> </group> <group targetFramework="sl30"> </group> </dependencies> 

Where version is:

The range of versions acceptable as a dependency. Typically this is just a version number which represents a minimum version. However a more explicit version range syntax is supported.

( update : updated references to more recent version of nuget)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM