How do I specify conditional dependencies based on target framework in NuGet?

nuget, nuspec

Solution

Yeah, that's pretty much correct. Details on portable framework names can be found here http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Framework_Names

One more thing I found, since win+sl50+wp8 by default includes net45 you might want to include it so that this dependency group gets installed.

Problem

I am building a NuGet package that references the Microsoft CommonServiceLocator assembly. There are two versions of the Microsoft CommonServiceLocator out there: - CommonServiceLocator - targets the full .NET framework and is referenced by the Microsoft EnterpriseLibrary components. - Portable.CommonServiceLocator - contains both the full version of CommonServiceLocator and the recently released Portable Class Library version. My project is a Portable Class Library but, because it's sometimes used with Enterprise Library, I need to sort of "conditionally" reference the portable version so there's no conflict. - If the target framework is full .NET 4.0/4.5, use the original CommonServiceLocator package so people can also use the Enterprise Library bits (which also reference the CommonServiceLocator package). - If the target framework is portable (or anything else) use the Portable.CommonServiceLocator package. I see the new "group" feature in the NuGet docs showing how to specify dependencies in your .nuspec file and I think that will do what I want, but I'm not sure how to test it. Here's what I think I need to do and I'm hoping someone can validate my approach or point me in the right direction: ``` <dependencies> <group> <!-- Always include regardless of target framework --> <dependency id="Autofac" /> </group> <group targetFramework="net40"> <!-- Also include the full CSL if it's full framework --> <dependency id="CommonServiceLocator" /> </group> <group targetFramework="portable-win+sl50+wp8"> <!-- Otherwise include the Portable CSL --> <dependency id="Portable.CommonServiceLocator" /> </group> </dependencies> ``` Specifically... - Is my `targetFramework` syntax right? I can't find any examples, so I don't know if the `+` delimited mechanism is right or if it should be comma-delimited. - Will the default group work? That group with the unspecified target framework - will that always be included or do I need to copy/paste it in every group?

Original source