16

I am building a NuGet package that references the Microsoft CommonServiceLocator assembly.

There are two versions of the Microsoft CommonServiceLocator out there:

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?
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Travis Illig
  • 23,195
  • 2
  • 62
  • 85

1 Answers1

7

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.

Deepak
  • 2,223
  • 17
  • 15
  • If it's full net45, I want it to use the CommonServiceLocator, not the portable, so would I use this? targetFramework="net40+net45" – Travis Illig Dec 03 '12 at 21:15
  • nope, not required and it would work fine and use when installing on a project targeting net4.5 as it would rank the exact match higher than the portable library. and just specifying net40 would work as "When NuGet installs a package that has multiple assembly versions, it tries to match the framework name of the assembly with the target framework of the project. If a match is not found, NuGet copies the assembly that's for the highest version that is less than or equal to the project's target framework" – Deepak Dec 03 '12 at 21:54
  • Then it sounds like I actually do want to leave out the net45 reference and the rest of things should just fall into place. Perfect! Thanks! – Travis Illig Dec 03 '12 at 22:59