GetCustomAttribute () возвращает пустой указатель для AssemblyVersionAttribute

Я не знаком с Mac OS Виджеты Dashcode, но если бы они позволяют Вам пользоваться библиотеками JavaScript и поддерживать XMLHttpRequests, я использовал бы jQuery и сделал бы что-то вроде этого:

var page_content;
$.get( "somepage.php", function(data){
    page_content = data;
});

21
задан M. Dudley 17 July 2009 в 17:01
поделиться

3 ответа

The AssemblyVersionAttribute is not added to the assembly, but is treated in a "special" way by the compiler (i.e. it sets the version of the assembly)

You CAN get the AssemblyFileVersion attribute (i.e. this one is added to the assembly)

There are other attributes that show the same behavior: the AssemblyCultureAttribute and AssemblyFlagsAttribute are also used for setting assembly properties, and are not added to the assembly as custom attributes.

All of these attributes are listed under the Assembly Identity Attributes in the documentation. The documentation says this about these attributes:

Three attributes, together with a strong name (if applicable), determine the identity of an assembly: name, version, and culture.

18
ответ дан 29 November 2019 в 21:17
поделиться

Ваш пример не является временным решением. Это именно то, что вам следует делать в документации MSDN, что наводит меня на мысль, что код создан специально.
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx

Чтобы получить имя [sic] загруженной сборки, вызовите GetName в сборке, чтобы получить AssemblyName , а затем получите свойство Version . . Чтобы получить имя сборки, которую вы не загрузили, вызовите GetAssemblyName из клиентского приложения, чтобы проверить версию сборки, которую использует ваше приложение.

8
ответ дан 29 November 2019 в 21:17
поделиться

Не знаю, почему он так себя ведет. Вместо того, чтобы идти после AssemblyVersionAttribute, мы делаем следующее:

Version AssemblyVersion = someAssembly.GetName().Version;

Для AssemblyFileVersion мы используем:

Version fileVersion = new Version("0.0.0.0");
AssemblyFileVersionAttribute[] fileVersionAttributes = (AssemblyFileVersionAttribute[])assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true);
if (fileVersionAttributes != null && fileVersionAttributes.Length > 0) {
    fileVersion = new Version(fileVersionAttributes[0].Version);
}
6
ответ дан 29 November 2019 в 21:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: