I got a monitoring page where I show the version of all web parts, features etc.

If I use features with Event Receiver I can easily get the version. If the Feature has no event receiver I solved that by adding ReceiverAssembly="$SharePoint.Project.AssemblyFullName$" into the template.xml file.

This is the way I get the AssemblyFileversion of a solution

foreach (SPFeature feature in SPContext.Current.SiteFeatures)   
   string receiverAssembly = feature.Definition.ReceiverAssembly;
   object[] attributes = receiverAssembly.GetCustomAttributes(false);
   foreach (object attribute in attributes)
      if (attribute is System.Reflection.AssemblyFileVersionAttribute)
         return  ((System.Reflection.AssemblyFileVersionAttribute)attribute).Version;

All Fine. Now I got WebParts etc that have no Feature at all. If I create an object within one of that wsp manually I can get that information:

Log log = new Log();             
string toolVersion = GetAssemblyFileVersion(log.GetType().Assembly);      

("Log" is a class within a project without a feature)

So now I need the following: How do I get ALL WSPs without a feature and get the AssemblyFileVersion of that WSPs?



Depending on the complexity you can afford, one option might be to just plit open the WSPs in the solution store (or wherever you have them), extract the DLLs, and load them.


| improve this answer | |

A WSP could contain zero or more assemblies. Thus, not all WSPs would contain an assembly to get an AssemblyFileVersion from.

What I tend to do for those is just deploy a text file somewhere (like a subdirectory of Layouts) with version information in it.

Also, a WSP could contain multiple assemblies, and not all of those would necessarily be used directly by features (as you note).

The best that I can suggested is that you'd have to retrieve the actual WSP files for each Farm and Sandbox solution in the farm, unpack them, and look for .dll files, which sounds like a) a lot of work, and b) possibly tricky from a security standpoint.

Personally, I tend to simply output the assembly file version in an HTML comment in my web parts.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.