Reputation: 34840
Given a assembly how do I determine (in code) what version of Silverlight that assembly is compiled against?
So I want a method that does this
public static decimal GetSilverlightVersion(string assemblyPath)
{
Magic goes here
}
and it should return 2.0, 3.0 or 4.0
Note: the executing code is .net 4 not Silverlight
Upvotes: 1
Views: 212
Reputation: 941465
The compiler embeds the [TargetFramework] attribute into the assembly. You can read it back at runtime with reflection. Some sample code:
var asm = System.Reflection.Assembly.GetExecutingAssembly();
var attr = asm.GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false)
as System.Runtime.Versioning.TargetFrameworkAttribute[];
if (attr.Length > 0) {
label1.Content = attr[0].FrameworkDisplayName;
}
Displayed value on my machine: "Silverlight 4".
Upvotes: 1