Модераторы: Partizan, gambit
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> AssemblyVersionAttribute 
:(
    Опции темы
Bogdan1024
  Дата 26.11.2007, 11:40 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Завсегдатай
Сообщений: 1436
Регистрация: 28.9.2005
Где: Киев

Репутация: 5
Всего: 13



Сборка явно помечена аттрибутом AssemblyVersionAttribute. Почему этот код ничего не выводит?
Код

                object[] attributes2 = a.GetCustomAttributes(typeof(System.Reflection.AssemblyVersionAttribute), true);
                if (attributes2.Length > 0)
                {
                    System.Reflection.AssemblyVersionAttribute ava = (System.Reflection.AssemblyVersionAttribute)attributes2[0];
                    System.Console.WriteLine("Версия сборки : {0}.", ava.Version);
                }

Тоесть, attributes2.Length == 0 всё время.
И если выводить все атрибуты сборки, то её там тоже нету :(


--------------------
user posted image
PM MAIL   Вверх
tol05
Дата 26.11.2007, 13:15 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Участник Клуба
Сообщений: 1632
Регистрация: 21.12.2006
Где: Харьков

Репутация: 63
Всего: 170



а почему не 
Код

System.Console.WriteLine("Версия сборки : {0}.", a.GetName().Version);

? smile

Цитата

The assembly version is NOT a custom attribute. Unfortunately, the C# syntax confuses the issue. [AssemblyVersion] is a message to the compiler to tell the compiler to set the version metadata of the assembly to the specified value. As Adam pointed out, you get the version through the name of the assembly, not through a custom attribute.

C# is quite sloppy in this respect. For example [AssemblyKeyFile] is a message to the compiler to use a specific key file to sign the assembly and create the public key token for the strong name. The path and name of the key file is of no use at all to the runtime, nor to anyone else, but the C# compiler will add a custom attribute (.custom metadata) for the key file in your assembly! This is totally unnecessary and it leaks possibly personal information (do you want your customers to know the name of your build folder?). In .NET 2.0 the C# compiler allows you to use a command line switch to pass the name of the key file and so the ..custom attribute is not created. (However, code that uses [AssemblyKeyFile] will still create the .custom metadata on .NET 2.0.)

взято отсюда

Это сообщение отредактировал(а) tol05 - 26.11.2007, 13:30


--------------------
На хорошей работе и сны хорошие снятся.
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Прежде чем создать тему, посмотрите сюда:
mr.DUDA
THandle

Используйте теги [code=csharp][/code] для подсветки кода. Используйтe чекбокс "транслит" если у Вас нет русских шрифтов.
Что делать если Вам помогли, но отблагодарить помощника плюсом в репутацию Вы не можете(не хватает сообщений)? Пишите сюда, или отправляйте репорт. Поставим :)
Так же не забывайте отмечать свой вопрос решенным, если он таковым является :)


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, mr.DUDA, THandle.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Общие вопросы по .NET и C# | Следующая тема »


 




[ Время генерации скрипта: 0.0432 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.