Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / September 2004

Tip: Looking for answers? Try searching our database.

CodeModel, [assebly:] attributes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oleg Ogurok - 20 Sep 2004 05:14 GMT
Hi all,

I'm trying to write an Add-on in C# to modify attributes applied to the
assembly itself, e.g. (in AssemblyInfo.cs)

[assembly: AssemblyVersion("1.0.*")]

What's the best approach? I'd like to use CodeModel, but I'm having
difficulties.
I'm enumerating through the collection of a project's CodeElements to find
AssemblyVersionAttribute.
Once I've found it, I'm trying to retrieve .StartPoint of it but getting a
COM exception 0x80004005 Unspecified error.
Also, I'm searching for the class recursively in my GetClass() method, and
it returns too many classes, even those that don't exist in my code.

Any help is greatly appreciated.

Here's my code:

       foreach (CodeElement codeElement in project.CodeModel.CodeElements)
       {
        if (codeElement is CodeNamespace || codeElement is CodeClass)
        {
         GetClass(codeElement, ref output);
       }
....
 private void GetClass(CodeElement codeElement, ref string output)
 {

  if (codeElement is CodeClass)
  {
   output += ", " + codeElement.FullName;

   CodeClass cc = (CodeClass)codeElement;
   if (cc.FullName ==
typeof(System.Reflection.AssemblyVersionAttribute).FullName)
   {
    TextPoint startPoint = cc.StartPoint;
   }

  }
  CodeElements subElements = null;
  if (codeElement is CodeClass)
  {
   subElements = ((CodeClass)codeElement).Members;
  }
  else if (codeElement is CodeNamespace)
  {
   subElements = ((CodeNamespace)codeElement).Members;
  }

  if (subElements != null)
  {
   foreach (CodeElement subElement in subElements)
   {
    if (subElement is CodeClass || subElement is CodeNamespace)
     GetClass(subElement, ref output);
   }
  }
 }
Chetan Chudasama - 29 Sep 2004 02:14 GMT
Oleg,

What version of VS are you using: VS 2003 or Whidbey Beta 1?

The Project.CodeModel is most useful for VC++ projects (see documentation
at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
ml/vxlrfcodemodelproperty.asp). If your addin will work on C# or VB
projects then you need to use FileCodeModel object.

Even when you use the FileCodeModel, the support is not very good in VS
2003 and you may still not be able to get the AssemblyAttributes in the
AssemblyInfo file.

The CodeModel support has been greatly improved in Whidbey and coding up
what you are trying to do is very easy and straight forward.

- Chetan [Extensibility QA, MSFT]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.