How to get expanded path from EnvDTE / VCProjectEn

2019-08-29 12:44发布

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条回答
在下西门庆
2楼-- · 2019-08-29 13:28

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);
查看更多
登录 后发表回答