【问题标题】:How to set linker options for VC project using EnvDTE如何使用 EnvDTE 为 VC 项目设置链接器选项
【发布时间】:2016-07-07 19:57:31
【问题描述】:

我正在使用 EnvDTE 在 Visual Studio 插件中修改 VC 项目的链接器和编译器设置/选项。但我似乎找不到可以从 DTE 实例访问这些选项的位置。到目前为止我所拥有的是

// I successfully can open the solution and get the project I'd like to
// modify the build options of (compiler and linker options)
foreach (EnvDTE.Project p in VS2015Instance.Solution.Projects)
{
      if(p.UniqueName.Contains(projectName))
      {
            // At this point I have a reference to my VC project.
            // Here I'd like to set some linker option before building the
            // project.
            VS2015Instance.ExecuteCommand("Build.BuildSolution");
      }
}

那么,我在哪里可以获取/设置这些选项?

【问题讨论】:

    标签: c# c++ visual-studio automation envdte


    【解决方案1】:

    我最终使用 Microsoft.VisualStudio.VCProjectEngineEnvDTE 来做我想做的事情:

     VCLinkerTool linker;
     foreach (EnvDTE.Project p in VS2015Instance.Solution.Projects)
     {
         if (p.UniqueName.Contains(project.Name))
         {
             var prj = (VCProject)p.Object;
             var cfgs = (IVCCollection)prj.Configurations;
             foreach (VCConfiguration cfg in cfgs)
             {
                 if (cfg.ConfigurationName.Contains("Debug"))
                 {
                    var tools = (IVCCollection)cfg.Tools;
                    foreach (var tool in tools)
                    {
                        if (tool is VCLinkerTool)
                        {
                            linker = (VCLinkerTool)tool;
                            // now I can use linker to set its options.
                            break;
                         }
                    }
                    break;
                  }
              }
              break;
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 2022-10-24
      • 1970-01-01
      • 2014-04-07
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多