C# VCLinkerTool 添加附加依赖库

  • Post author:
  • Post category:其他


C# 写VSIX插件,实现功能:实验实例中,添加一个.sln项目,复制一个文件夹到该项目中,将该文件夹中的所有.lib自动添加附加依赖库中

在这里插入图片描述

// 添加附加依赖库
public void AdditionalLinker(string strToPath)
{
    ThreadHelper.ThrowIfNotOnUIThread();
    VCProject prj;
    IVCCollection cfgs, tools;
    VCConfiguration cfg;
    VCLinkerTool tool;
    StringBuilder sb = new StringBuilder();
    
    DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2;
    prj = (VCProject)dte2.Solution.Projects.Item(1).Object;
    cfgs = (IVCCollection)prj.Configurations;
    cfg = (VCConfiguration)cfgs.Item(1);
    tools = (IVCCollection)cfg.Tools;
    tool = (VCLinkerTool)tools.Item("VCLinkerTool");
    tool.AdditionalLibraryDirectories = strToPath;
    GetFiles files = new GetFiles();
    foreach (string item in files. Readlist(strToPath,".lib"))
    {
        tool.AdditionalDependencies = tool.AdditionalDependencies + "\r\n" + item.Substring(item.LastIndexOf("\\") + 1, item.Length - item.LastIndexOf("\\") - 1); ;
    }
}

GetFiles类Readlist(strToPath,”.lib”)返回strToPath路径下所有.lib后缀的文件,参见上篇博文。

在这里插入图片描述

在这里插入图片描述



版权声明:本文为weixin_38973882原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。