Question to NuGet guru's - how to get target framework version of a package?

62 views
Skip to first unread message

Gleb Chermennov

unread,
Mar 4, 2013, 2:47:58 PM3/4/13
to fubumv...@googlegroups.com
NuGet keeps surprising me. And its API, of course.
Does anybody know an answer to a simple question - how to get target framework version (e.g. 3.5, 4.0, etc.) of a package via API?
I tried IPackageMetadata.FrameworkAssemblies property, but it seems to be always empty, as far as I can tell.
I'm sure you're already did this in Ripple at some point, I just can't find it.
I'm sorry if it's very dumb.

Jeremy D. Miller

unread,
Mar 4, 2013, 3:04:06 PM3/4/13
to fubumv...@googlegroups.com
*I* couldn't figure it out, even stepping through the nuget code.  I cheated and hard-coded it to 4.0 in my ripple spikes.

Not the answer you're wanting, but maybe someone else will know.

--
You received this message because you are subscribed to the Google Groups "FubuMVC Development Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fubumvc-deve...@googlegroups.com.
To post to this group, send email to fubumv...@googlegroups.com.
Visit this group at http://groups.google.com/group/fubumvc-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gleb Chermennov

unread,
Mar 4, 2013, 3:50:00 PM3/4/13
to fubumv...@googlegroups.com
So, I'm not insane. That's good. 
It have occurred to me that MS forgot to publish this info :)

вторник, 5 марта 2013 г., 0:04:06 UTC+4 пользователь Jeremy Miller написал:

Jeremy D. Miller

unread,
Mar 4, 2013, 3:50:56 PM3/4/13
to fubumv...@googlegroups.com
It's in there somewhere, I'm just not sure how it's doing it.  Silly me, I thought it would surely be in the class that reads and writes to csproj files, but that's not where it is.

Gleb Chermennov

unread,
Mar 5, 2013, 4:36:36 AM3/5/13
to fubumv...@googlegroups.com
I gave up for the time being. But for sure I'll come back later.


вторник, 5 марта 2013 г., 0:04:06 UTC+4 пользователь Jeremy Miller написал:
*I* couldn't figure it out, even stepping through the nuget code.  I cheated and hard-coded it to 4.0 in my ripple spikes.

Gleb Chermennov

unread,
Mar 5, 2013, 4:49:18 AM3/5/13
to fubumv...@googlegroups.com
I created a discussion on NuGet codeplex site http://nuget.codeplex.com/discussions/435408.
Let's see how that will turn out.

вторник, 5 марта 2013 г., 13:36:36 UTC+4 пользователь Gleb Chermennov написал:

Rob Reynolds

unread,
Mar 5, 2013, 12:05:23 PM3/5/13
to fubumv...@googlegroups.com
I'm guessing it's done strictly client side by inspecting the package contents. Unfortunately. I responded to your post on codeplex as well.

Jeremy D. Miller

unread,
Mar 5, 2013, 12:09:00 PM3/5/13
to fubumv...@googlegroups.com
Rob,

I think he's asking how to query the VS csproj/sln files to know what version they are.

- Jeremy

Gleb Chermennov

unread,
Mar 5, 2013, 12:13:13 PM3/5/13
to fubumv...@googlegroups.com
No-no-no, I asked about the NuGet packages. I know how to get target framework from a .csproj file.

вторник, 5 марта 2013 г., 21:09:00 UTC+4 пользователь Jeremy Miller написал:

Gleb Chermennov

unread,
Mar 5, 2013, 12:44:46 PM3/5/13
to fubumv...@googlegroups.com
This is really awesome - they know about the problem for about a year and moved it to the backlog. Hilarious.
http://nuget.codeplex.com/workitem/1908

вторник, 5 марта 2013 г., 21:13:13 UTC+4 пользователь Gleb Chermennov написал:

Matt S.

unread,
Mar 5, 2013, 12:55:08 PM3/5/13
to fubumv...@googlegroups.com
Gleb is on a mission now!

Gleb Chermennov

unread,
Mar 11, 2013, 6:14:35 PM3/11/13
to fubumv...@googlegroups.com
I think I found how NuGet does it's job - they do project file editing dance through their own API with help of some VS built-in magic.
Now all I have to do is calculate target framework version for a package. Seems an easy task for tomorrow evening :)

вторник, 5 марта 2013 г., 21:55:08 UTC+4 пользователь Matt S. написал:

Gleb Chermennov

unread,
Mar 11, 2013, 6:53:04 PM3/11/13
to fubumv...@googlegroups.com
Nah. I'm officially giving up.
It seems that they only provide a target framework when it's EXPLICITLY SET - that is, if package author was careful and published his library using .net-{versionNumber} convention.
That's not enough. Screw MS. 

вторник, 12 марта 2013 г., 2:14:35 UTC+4 пользователь Gleb Chermennov написал:

Gleb Chermennov

unread,
Mar 18, 2013, 5:36:19 PM3/18/13
to fubumv...@googlegroups.com
For the curious ones, I did find out how to do this via official API. Hell, guys in Redmond should really document their stuff.
First of all, my initial assumption was wrong - package doesn't have a target framework, neither does it's specific version. 
I did fairly simply experiment:

var repoBuilder = new PackageRepositoryBuilder();
var aggregateRepository = repoBuilder.BuildRemote();
var mspec = serviceBasedRepository.FindPackagesById("Machine.Specifications").FirstOrDefault(x => x.Version == SemanticVersion.Parse("0.5.12"));

That last line gets a version of MSpec package. If now we query mspec.AssemblyReferences, we'll see 3 items - each with its own target framework (actually filled, this time) and a relative path against packages folder.
It can also happen that the package doesn't have separate binaries for different framework versions - in this case, there'll be an item with target framework = null, residing in \packages\{packageId}.{packageVersion}\lib folder.
I think it's safe to assume that target framework in this case can be obtained via Assembly.ImageRuntimeVersion, as described here: http://stackoverflow.com/questions/6854664/retrieve-target-framework-version-and-target-framework-profile-from-a-net-assem 

Of course, same principles apply if package version contains several assembly references for one runtime - that is, NHibernate at some point consisted of 3 assemblies, Castle, Linq support and NH itself. The item count in AssemblyReferences collection will then be <amountOfReferencedAssemblies>*<amountOfRuntimesSupported>.

вторник, 12 марта 2013 г., 2:53:04 UTC+4 пользователь Gleb Chermennov написал:

Joshua Arnold

unread,
Mar 18, 2013, 7:15:34 PM3/18/13
to fubumv...@googlegroups.com
Gleb,

You might want to pay attention to my commits on this branch:

See if our new work lines up with your way of wanting to work with NuGet.

Gleb Chermennov

unread,
Mar 19, 2013, 1:34:45 AM3/19/13
to fubumv...@googlegroups.com
I'll definitely take a look.

вторник, 19 марта 2013 г., 3:15:34 UTC+4 пользователь jmarnold написал:
Reply all
Reply to author
Forward
0 new messages