Reputation: 33607
I'm working on an extension that targets C++ projects. It needs to retrieve a list of IncludePaths for a project. In VS IDE, it's menu -> Project -> Properties -> Configuration properties -> C++ -> General -> Additional Include Directories. That's what I need to get programmatically in my extension.
I have a corresponding VCProject instance, I also have a VCConfiguration instance. Judging from the Automation Model Overview chart, the project and configuration both have a collection of properties. However, they don't seem to available. Neither VCConfiguration nor VCProject classes have any property collection, not even when I inspect the contents of VCConfiguration and VCProject objects at runtime.
MSDN docs also don't provide any insights. VCConfiguration interface has a property PropertySheets, but after examining it at runtime with the help of debugger I have determined it's not what I need.
P. S. If I could just get the value of Command Line property (Project -> Properties -> Configuration properties -> C++ -> Command Line), the list of arguments compiler will be called with for a given project - that's also fine by me, one can parse that string to get all include paths.
Upvotes: 0
Views: 284
Reputation: 8783
You'll probably want to remove some of my extra crap... but this should do the trick:
public string GetCommandLineArguments( Project p )
{
string returnValue = null;
try
{
if ( ( Instance != null ) )
{
Properties props = p.ConfigurationManager.ActiveConfiguration.Properties;
try
{
returnValue = props.Item( "StartArguments" ).Value.ToString();
}
catch
{
returnValue = props.Item( "CommandArguments" ).Value.ToString();
// for c++
}
}
}
catch ( Exception ex )
{
Logger.Info( ex.ToString() );
}
return returnValue;
}
These will probably help, too: (so you can see what properties a project has and their values)
public void ShowProjectProperties( Project p )
{
try
{
if ( ( Instance != null ) )
{
string msg = Path.GetFileNameWithoutExtension( p.FullName ) + " has the following properties:" + Environment.NewLine + Environment.NewLine;
Properties props = p.ConfigurationManager.ActiveConfiguration.Properties;
List< string > values = props.Cast< Property >().Select( prop => SafeGetPropertyValue( prop) ).ToList();
msg += string.Join( Environment.NewLine, values );
MessageDialog.ShowMessage( msg );
}
}
catch ( Exception ex )
{
Logger.Info( ex.ToString() );
}
}
public string SafeGetPropertyValue( Property prop )
{
try
{
return string.Format( "{0} = {1}", prop.Name, prop.Value );
}
catch ( Exception ex )
{
return string.Format( "{0} = {1}", prop.Name, ex.GetType() );
}
}
Upvotes: 1