var attr = Assembly
.GetEntryAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
as AssemblyInformationalVersionAttribute[];
Si tratta di una serie di AssemblyInformationalVersionAttribute
. Non è mai nullo anche se non ci sono attributi del tipo cercato.
var attr2 = Attribute
.GetCustomAttribute(
Assembly.GetEntryAssembly(),
typeof(AssemblyInformationalVersionAttribute))
as AssemblyInformationalVersionAttribute;
Questo può essere nullo se l'attributo non è presente.
var attr3 = Attribute
.GetCustomAttributes(
Assembly.GetEntryAssembly(),
typeof(AssemblyInformationalVersionAttribute))
as AssemblyInformationalVersionAttribute[];
Come prima.
Vedere http://stackoverflow.com/a/19008850/116895 – lance
Si noti che questo codice non funziona se l'assembly non è stato caricato da file o UNC. Questo potrebbe essere il caso se l'assembly è incorporato in un altro assembly (in genere quando nascondi gli assembly) o per qualche altra ragione è stato caricato usando 'Assembly.Load (byte [])' – larsmoa
Inoltre, non funziona se hai 'mkbundle 'd la tua applicazione per Mono – Cocowalla