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 / May 2006

Tip: Looking for answers? Try searching our database.

Using VCCustomBuildRule

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gordon - 17 May 2006 00:40 GMT
Hi,
 VS2005 includes the ability to define custom build rules. I've
successfully added one and defined various properties for it. Further,
I have an addin that looks at the files attached to the custom build
rule and I'd like to change some of the properties associated with the
files. I can't figure out how to set the properties.

1) I get the VCCustomBuildRule object from the file's configuration. I
can do this no problem, and examining the rule makes it clear I've got
the right thing. Further, looking at it in the IDE also shows that it
is the right thing.

2) I've defined a new property, called "ForcedIncludes'. Using
VCCustomBuildRule's Properties collection, I can get the
VCRuntimeStringProperty object. I can examine its contents and see all
the settings for the property.

3) How do I set the actual value associated with that property? I'd
like to set it to "btag.hpp", for example. And once set, I'd like to be
able to right click on the file in the IDE and see the properties
associated with the custom build rule, and see the "ForcedInclude"
property set to "btag.hpp". The VCRuntimeStringProperty doesn't have a
spot to set the "value", however.

 It is as if I'm missing a object or interface. I searched through the
automation interface documentation on msdn2 and couldn't find anything
that looked reasonable. But I could have easily overlooked it. Any help
much appreciated!

 Cheers,
   Gordon.
Gordon - 18 May 2006 00:03 GMT
Hi,
 No joy yet; I've tried several other things. But it occured to me
this is a COM object. Is there a way to query it to see what interfaces
it is capable of? I could use that to see if there is a hidden
interface that I don't know about for this object that would allow me
to set one of the custom properties.

 Cheers,
   Gordon.
Gordon - 29 May 2006 16:48 GMT
Hi,
 I have been in contact with a PM inside Microsoft and they send me
the following solution:

Once you have VCCustomBuildRule, then you can set a property as
follows:

try
{
   VCCustomBuildRule vcfilebuildrule =
(VCCustomBuildRule)vcfileconfiguration.Tool; //this cast may fail if
tool is not a custom build rule tool, use try/catch

   if (vcfilebuildrule.Name == "BisonParser")
       vcfilebuildrule.GetType().InvokeMember("RenameExternalSymbols",
BindingFlags.PutDispProperty, null, vcfilebuildrule, new object[1] {
"ddd" });
}
catch (Exception) { ... }

 Change "BisonParser" to the name of your custom build rule, and
"RenameExternalSymbols" to be the name of the property that you are
changing. Basically, in C#, you have to deal with a late binding
problem!

 One other thing I got caught with. If you are trying to change a
file's build rule to use the custom build rule, then you should do the
following:

           IVCCollection fileConfigurations =
(IVCCollection)vc_file.FileConfigurations;
           foreach (VCFileConfiguration config in fileConfigurations)
           {
               VCConfiguration proj_config =
(VCConfiguration)config.ProjectConfiguration;

               VCCustomBuildRule cr =
(VCCustomBuildRule)(((IVCCollection)(proj_config.Tools)).Item("rootcint_build"));
               if (cr == null)
               {
                   throw new ArgumentException("There is not
rootcint_build tool for this configuration!");
               }

               config.Tool = cr;

               ///
               /// Now, grab the config (of which the Tool property
above has made a copy) and correctly set
               /// its various values.
               ///

               ConfigureLinkdefBuildOptions((VCCustomBuildRule)
config.Tool, vc_file, prj);
           }

Where ConfigureLinkdefBuildOptions is what actually sets the properties
(the try/catch handler above woudl go in this routine). The key is to
use config.Tool when you call it. If you use "cr" you'll be accessing
the build rule instance for the whole project. The config.Tool property
seems to make a copy of all the configuration parameters.

 I hope this helps!

 Cheers,
   Gordon.

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.