问题
I am trying to write a tool to create a zip file containing all PDBs files from one Visual Studio 2010 solution.
I can get every PDB filepath in the solution with the following code. However, the property value contains Visual Studio macro like $(TargetDir), $(TargetName) and so on.
Is there a function in the EnvDTE API to expand those macros to their current values ?
On the other hand, any other methods that would achieve my initial goal are also welcome !
Thanks
System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
object obj = Activator.CreateInstance(t, true);
DTE dte = (DTE)obj;
Solution sln = dte.Solution;
sln.Open(args[0]);
while (sln.IsOpen == false)
{
System.Threading.Thread.Sleep(100);
}
sln.SolutionBuild.SolutionConfigurations.Item("Release").Activate();
foreach (EnvDTE.Project project in sln.Projects)
{
Console.WriteLine("Inspecting project {0}", project.Name);
VCProject vcproj = (VCProject)project.Object;
if (vcproj == null) // this is not a visual c++ project
continue;
IVCCollection cfgs = vcproj.Configurations;
VCConfiguration cfg = cfgs.Item(1);
VCLinkerTool tool = cfg.Tools("VCLinkerTool");
if (tool == null) // this is not a DLL/EXE project
continue;
Console.WriteLine("Program database = " + tool.ProgramDatabaseFile);
}
回答1:
I haven't tried this with VS2010, but in VS2008 you can call VCConfiguration.Evaluate to do this. In your example, it would be something like this:
string evaluatedPdbPath = cfg.Evaluate(tool.ProgramDatabaseFile);
来源:https://stackoverflow.com/questions/8477011/how-to-get-expanded-path-from-envdte-vcprojectengine