How to get expanded path from EnvDTE / VCProjectEngine

风流意气都作罢 提交于 2020-01-16 16:59:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!