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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

If it's full net45, I want it to use the CommonServiceLocator, not the portable, so would I use this? targetFramework="net40+net45"
nope, not required and it would work fine and use <group targetFramework="net40"> 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"
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.