Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed AssemblyFileVersion in resource/constant/string/other?

I have been reading the AssemblyFileVersion using code similar to this but can no longer use Assembly.GetExecutingAssembly (or any methods in the Assembly namespace) due to security restrictions.

(As an aside - this is the security restrictions imposed by SharePoint Online which does some interrogation of your assembly upon upload and rejects it if you use certain forbidden parts of the framework)

So are there any other ways of getting the Assembly File Version?

I am guessing no, so are there any ways of putting the AssemblyFileVersion attribute from AssemblyInfo.cs into something like a resource file or a constant so it can be accessed at runtime without using GetExectingAssembly?

like image 217
Ryan Avatar asked Feb 18 '23 19:02

Ryan


1 Answers

This is what I've come up with. Fugly but meets goals (single place where AssemblyFileVersion is defined) without any MSBuild tricks to write out AssemblyFileVersion into resource file.

File : AssemblyInfo.cs

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyProject")]
...
[assembly: AssemblyFileVersion(MyProject.AssemblyInfo.AssemblyFileVersion)]

namespace MyProject
{
    static internal class AssemblyInfo
    {
        /// <summary>
        /// The AssemblyFileVersion of this web part
        /// </summary>
        internal const string AssemblyFileVersion = "1.0.3.0";
    }
}
like image 54
Ryan Avatar answered Mar 10 '23 10:03

Ryan