// ******************************************************************

        /// <summary>
        /// Reads the value of the <see cref="AssemblyVersionAttribute"/>
        /// attribute for the given assembly.
        /// </summary>
        /// <param name="assembly">The assembly to read from.</param>
        /// <returns>The value of the given assembly's version attribute.</returns>
        public static string ReadAssemblyVersion(this Assembly assembly)
        {
            // Attempt to read the assembly's version attribute.
            object[] attributes = assembly.GetCustomAttributes(
                typeof(AssemblyVersionAttribute),
                true
                );

            // Did we fail?
            if (attributes.Length == 0)
            {
                return(string.Empty);
            }

            // Attempt to recover a reference to the attribute.
            AssemblyVersionAttribute attr =
                attributes[0] as AssemblyVersionAttribute;

            // Did we fail?
            if (attr == null || attr.Version.Length == 0)
            {
                return(string.Empty);
            }

            // Return the text for the attribute.
            return(attr.Version);
        }
        /// <summary>
        /// Gets the assembly information of the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly from which to extract the information from.</param>
        public static AssemblyInformation GetAssemblyInformation(this Assembly assembly)
        {
            string title       = assembly.GetCustomAttribute <AssemblyTitleAttribute>()?.Title;
            string description = assembly.GetCustomAttribute <AssemblyDescriptionAttribute>()?.Description;
            string company     = assembly.GetCustomAttribute <AssemblyCompanyAttribute>()?.Company;
            string product     = assembly.GetCustomAttribute <AssemblyProductAttribute>()?.Product;
            string copyright   = assembly.GetCustomAttribute <AssemblyCopyrightAttribute>()?.Copyright;
            string trademark   = assembly.GetCustomAttribute <AssemblyTrademarkAttribute>()?.Trademark;

            string versionS;
            AssemblyVersionAttribute assemblyVersion = assembly.GetCustomAttribute <AssemblyVersionAttribute>();

            if (assemblyVersion != null)
            {
                versionS = assemblyVersion.Version;
            }
            else
            {
                AssemblyFileVersionAttribute fileVersion = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>();
                versionS = fileVersion?.Version;
            }
            Version version = null;

            if (versionS != null)
            {
                version = Version.Parse(versionS);
            }

            return(new AssemblyInformation(title, description, company, product, copyright, trademark, version));
        }
        public HttpResponseMessage ServiceInfo()
        {
            Assembly ass = this.GetType().Assembly;
            AssemblyProductAttribute assPrd = ass.GetCustomAttributes(typeof(AssemblyProductAttribute), false).FirstOrDefault() as AssemblyProductAttribute;
            AssemblyInformationalVersionAttribute assInfVer = ass.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault() as AssemblyInformationalVersionAttribute;
            AssemblyVersionAttribute assVer = ass.GetCustomAttributes(typeof(AssemblyVersionAttribute), false).FirstOrDefault() as AssemblyVersionAttribute;

            Entities.ServiceInfo svcInfo = new Entities.ServiceInfo();
            svcInfo.ServiceName    = assPrd == null ? "<n/a>" : assPrd.Product;
            svcInfo.ProductVersion = assInfVer == null ? "<n/a>" : assInfVer.InformationalVersion;
            svcInfo.BuildVersion   = assVer == null ? "<n/a>" : assVer.Version;

            AppDomain.CurrentDomain.GetAssemblies().ToList()
            .Where(w => w.CodeBase.StartsWith(ass.CodeBase))
            .ToList().ForEach(a => {
                svcInfo.AssemblyVersions.Add(new Entities.AssemblyVersion()
                {
                    NameOfAssembly    = a.GetName().FullName,
                    VersionOfAssembly = a.ImageRuntimeVersion
                });
            });

            HttpResponseMessage msg = Request.CreateResponse <Entities.ServiceInfo>(System.Net.HttpStatusCode.OK, svcInfo);

            return(msg);
        }
        public AssemblyVersionAttributeTest()
        {
            //create a dynamic assembly with the required attribute
            //and check for the validity

            dynAsmName.Name = "TestAssembly";

            dynAssembly = Thread.GetDomain().DefineDynamicAssembly(
                dynAsmName, AssemblyBuilderAccess.Run
                );

            // Set the required Attribute of the assembly.
            Type            attribute = typeof(AssemblyVersionAttribute);
            ConstructorInfo ctrInfo   = attribute.GetConstructor(
                new Type [] { typeof(string) }
                );
            CustomAttributeBuilder attrBuilder =
                new CustomAttributeBuilder(ctrInfo, new object [1] {
                "1.2.3.4"
            });

            dynAssembly.SetCustomAttribute(attrBuilder);
            object [] attributes = dynAssembly.GetCustomAttributes(true);
            attr = attributes [0] as AssemblyVersionAttribute;
        }
Beispiel #5
0
 public ProjectAttributes()
 {
     _assemblyTitleAttribute       = GetAttribute <AssemblyTitleAttribute>();
     _assemblyDescriptionAttribute = GetAttribute <AssemblyDescriptionAttribute>();
     _assemblyVersionAttribute     = GetAttribute <AssemblyVersionAttribute>();
     _assemblyCompanyAttribute     = GetAttribute <AssemblyCompanyAttribute>();
     _assemblyCopyrightAttribute   = GetAttribute <AssemblyCopyrightAttribute>();
 }
Beispiel #6
0
        public static string GetVersion([NotNull] this Assembly thisValue)
        {
            AssemblyVersionAttribute assemblyVersion = thisValue.GetCustomAttribute <AssemblyVersionAttribute>();

            if (assemblyVersion != null)
            {
                return(assemblyVersion.Version);
            }
            return(Convert.ToString(thisValue.GetName().Version));
        }
        public static void AssemblyVersionAttributeTests()
        {
            var attr1 = new AssemblyVersionAttribute(null);

            Assert.Null(attr1.Version);

            var attr2 = new AssemblyVersionAttribute("5.6.7.8.9");

            Assert.Equal("5.6.7.8.9", attr2.Version);
        }
        public static string GetAssemblyVersion(this System.Reflection.Assembly @this)
        {
            AssemblyVersionAttribute attr = @this.GetCustomAttribute <AssemblyVersionAttribute>();
            string returnValue            = null;

            if (attr != null)
            {
                returnValue = attr.Version;
            }
            return(returnValue);
        }
Beispiel #9
0
        private void Get_AllVariables(Assembly a)
        {
            AssemblyTitleAttribute       titleAttr   = null;
            AssemblyDescriptionAttribute descAttr    = null;
            AssemblyCopyrightAttribute   copyAttr    = null;
            AssemblyProductAttribute     prodAttr    = null;
            AssemblyTrademarkAttribute   tradeAttr   = null;
            AssemblyCultureAttribute     cultureAttr = null;
            AssemblyVersionAttribute     versionAttr = null;
            AssemblyCompanyAttribute     companyAttr = null;

            try
            {
                titleAttr   = a.GetCustomAttribute <AssemblyTitleAttribute>() ?? new AssemblyTitleAttribute("No assembly title");
                descAttr    = a.GetCustomAttribute <AssemblyDescriptionAttribute>() ?? new AssemblyDescriptionAttribute("No description");
                copyAttr    = a.GetCustomAttribute <AssemblyCopyrightAttribute>() ?? new AssemblyCopyrightAttribute("No copyright");
                prodAttr    = a.GetCustomAttribute <AssemblyProductAttribute>() ?? new AssemblyProductAttribute("No product information");
                tradeAttr   = a.GetCustomAttribute <AssemblyTrademarkAttribute>() ?? new AssemblyTrademarkAttribute(string.Empty); // Trademark was in older .Net 3.5 apps but has not made its way into .Net Core
                cultureAttr = a.GetCustomAttribute <AssemblyCultureAttribute>() ?? new AssemblyCultureAttribute("en-US");
                versionAttr = a.GetCustomAttribute <AssemblyVersionAttribute>() ?? new AssemblyVersionAttribute("0.0.0.0");
                companyAttr = a.GetCustomAttribute <AssemblyCompanyAttribute>() ?? new AssemblyCompanyAttribute("No company specified");

                this._title          = titleAttr.Title;
                this._description    = descAttr.Description;
                this._copywrite      = copyAttr.Copyright;
                this._product        = prodAttr.Product;
                this._trademark      = tradeAttr.Trademark;
                this._culture        = cultureAttr.Culture;
                this._appCultureInfo = new CultureInfo(this._culture);
                this._version        = versionAttr.Version;
                this._AppVersion     = new Version(this._version);
                this._company        = companyAttr.Company;
            }
            catch (Exception ex)
            {
                // Oh dear ...
                this._title       = "An error happened trying to get the application information.";
                this._description = string.Format("{0}. {1}", ex.GetType().ToString(), ex.Message);
            }
            finally
            {
                a           = null;
                descAttr    = null;
                copyAttr    = null;
                prodAttr    = null;
                tradeAttr   = null;
                cultureAttr = null;
                versionAttr = null;
                companyAttr = null;
                descAttr    = null;
                titleAttr   = null;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Returns the Addin Version String
 /// </summary>
 /// <param name="assembly">Addin Assembly</param>
 /// <returns>Version String</returns>
 private static string GetAssemblyVersionString(Assembly assembly)
 {
     object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
     if (attributes.Length > 0)
     {
         AssemblyVersionAttribute titleAttribute = (AssemblyVersionAttribute)attributes[0];
         if (titleAttribute.Version != "")
         {
             return(titleAttribute.Version);
         }
     }
     return("1.0.0.0");
 }
Beispiel #11
0
        /// <summary>
        /// Writes a logo to the specified output stream.
        /// </summary>
        /// <param name="output">A <see cref="T:System.IO.TextWriter" /> that represents an output stream.</param>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="output" /> is null.</exception>
        public static void WriteLogo(this TextWriter output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            Assembly entryAssembly = Assembly.GetEntryAssembly();
            AssemblyTitleAttribute assemblyTitleAttribute = entryAssembly.GetCustomAttribute <AssemblyTitleAttribute>();

            if (assemblyTitleAttribute == null)
            {
                output.Write(entryAssembly.FullName);
            }
            else
            {
                output.Write(assemblyTitleAttribute.Title);
            }

            output.Write(' ');
            output.Write('[');
            output.Write("Version");
            output.Write(' ');

            AssemblyVersionAttribute assemblyVersionAttribute = entryAssembly.GetCustomAttribute <AssemblyVersionAttribute>();

            if (assemblyVersionAttribute == null)
            {
                output.Write(entryAssembly.GetName().Version);
            }
            else
            {
                output.Write(assemblyVersionAttribute.Version);
            }

            output.WriteLine(']');

            AssemblyCopyrightAttribute assemblyCopyrightAttribute = entryAssembly.GetCustomAttribute <AssemblyCopyrightAttribute>();

            if (assemblyCopyrightAttribute != null)
            {
                output.WriteLine(assemblyCopyrightAttribute.Copyright.Replace("©", "(c)"));
            }

            output.WriteLine();
        }
        public static String GetAssemblyVersion(this Assembly asm)
        {
            AssemblyVersionAttribute asmVersion = asm.GetAsmVersion();

            if (asmVersion != null)
            {
                return(asmVersion.Version);
            }

            AssemblyFileVersionAttribute asmFileVersion = asm.GetAsmFileVersion();

            if (asmFileVersion != null)
            {
                return(asmFileVersion.Version);
            }

            return("1.0.0.0");
        }
Beispiel #13
0
 private void loadVersion()
 {
     version = "0.0.0.0";
     try
     {
         if (obj != null)
         {
             AssemblyVersionAttribute version_attr = obj.GetCustomAttribute <AssemblyVersionAttribute>();
             if (version_attr != null)
             {
                 version = version_attr.Version;
             }
         }
     }
     catch
     {
         _load_fail = true;
     }
 }
Beispiel #14
0
        public AboutDialog(Window parent) : base(parent, "AboutDialog")
        {
            string title   = string.Empty;
            string version = string.Empty;

            var assembly = Assembly.GetExecutingAssembly();

            var titleAttributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);

            if (titleAttributes.Length > 0)
            {
                AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)titleAttributes[0];
                if (!string.IsNullOrEmpty(titleAttribute.Title))
                {
                    title = titleAttribute.Title;
                }
            }

            var versionAttributes = assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false);

            if (versionAttributes.Length > 0)
            {
                AssemblyVersionAttribute versionAttribute = (AssemblyVersionAttribute)versionAttributes[0];
                if (!string.IsNullOrEmpty(versionAttribute.Version))
                {
                    version = versionAttribute.Version;
                }
            }

            Gtk.AboutDialog dialog = (Gtk.AboutDialog)base.Dialog;

            if (!string.IsNullOrEmpty(title))
            {
                dialog.ProgramName = title;
            }

            if (!string.IsNullOrEmpty(version))
            {
                dialog.Version = version;
            }
        }
            public Asm(Assembly asm)
            {
                Name = asm.FullName;
                if (!AssemblyUtilities.IsDynamic(asm))
                {
                    try
                    {
                        Location = asm.Location;
                    }
                    catch
                    {
                        // do nothing
                    }
                }

                if (string.IsNullOrEmpty(Location))
                {
                    Location = " ";
                }
                AssemblyFileVersionAttribute vatt = AssemblyUtilities.GetAttribute <AssemblyFileVersionAttribute>(asm);

                if (vatt != null)
                {
                    Version = vatt.Version;
                }
                else
                {
                    AssemblyVersionAttribute att = AssemblyUtilities.GetAttribute <AssemblyVersionAttribute>(asm);
                    if (att != null)
                    {
                        Version = att.Version;
                    }
                }
                InformationalVersion = AssemblyUtilities.GetInformationalVersion(asm);
                if (string.IsNullOrEmpty(Version))
                {
                    Version = InformationalVersion;
                }
                CompileDate = AssemblyUtilities.GetLinkerTimestamp(asm);
            }
        public void CtorTest()
        {
            var a = new AssemblyVersionAttribute("some text");

            Assert.AreEqual("some text", a.Version);
        }
        public void Ctor_String(string version)
        {
            var attribute = new AssemblyVersionAttribute(version);

            Assert.Equal(version, attribute.Version);
        }
Beispiel #18
0
        private static void CopyAssemblyVersion(AssemblyBuilder targetAssemblyBuilder, Assembly srcAsm)
        {
            Action <Type, string> AddCustomStringAttribute = (Type type, string content) =>
            {
                if (string.IsNullOrEmpty(content))
                {
                    return;
                }
                ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(string) });
                targetAssemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder(ctor, new object[] { content }));
            };
            bool hasInformationalVersionAttr = false;

            object[] attrs = srcAsm.GetCustomAttributes(false);
            foreach (var attr in attrs)
            {
                AssemblyCompanyAttribute cmp = attr as AssemblyCompanyAttribute;
                if (cmp != null)
                {
                    AddCustomStringAttribute(attr.GetType(), cmp.Company); continue;
                }
                AssemblyCopyrightAttribute copy = attr as AssemblyCopyrightAttribute;
                if (copy != null)
                {
                    AddCustomStringAttribute(attr.GetType(), copy.Copyright); continue;
                }
                AssemblyDescriptionAttribute da = attr as AssemblyDescriptionAttribute;
                if (da != null)
                {
                    AddCustomStringAttribute(attr.GetType(), da.Description); continue;
                }
                AssemblyFileVersionAttribute fva = attr as AssemblyFileVersionAttribute;
                if (fva != null)
                {
                    AddCustomStringAttribute(attr.GetType(), fva.Version);
                    if (!hasInformationalVersionAttr)
                    {
                        // Also set AssemblyInformationalVersionAttribute, if not set already.
                        // The unmanaged ProductVersion is taken from that attribute.
                        AddCustomStringAttribute(typeof(AssemblyInformationalVersionAttribute), fva.Version);
                    }
                    continue;
                }
                AssemblyInformationalVersionAttribute iva = attr as AssemblyInformationalVersionAttribute;
                if (iva != null)
                {
                    AddCustomStringAttribute(attr.GetType(), iva.InformationalVersion);
                    hasInformationalVersionAttr = true;
                    continue;
                }
                AssemblyProductAttribute pa = attr as AssemblyProductAttribute;
                if (pa != null)
                {
                    AddCustomStringAttribute(attr.GetType(), pa.Product); continue;
                }
                AssemblyTitleAttribute ta = attr as AssemblyTitleAttribute;
                if (ta != null)
                {
                    AddCustomStringAttribute(attr.GetType(), ta.Title); continue;
                }
                AssemblyTrademarkAttribute tm = attr as AssemblyTrademarkAttribute;
                if (tm != null)
                {
                    AddCustomStringAttribute(attr.GetType(), tm.Trademark); continue;
                }
                AssemblyVersionAttribute va = attr as AssemblyVersionAttribute;
                if (va != null)
                {
                    AddCustomStringAttribute(attr.GetType(), va.Version); continue;
                }
            }
            targetAssemblyBuilder.DefineVersionInfoResource();
        }