如何以编程方式向项目添加程序集引用?

编程入门 行业动态 更新时间:2024-10-26 15:25:40
本文介绍了如何以编程方式向项目添加程序集引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试使用 Roslyn 来解析解决方案文件,并以编程方式向解决方案中的每个项目添加自定义程序集引用.

I have been trying to use Roslyn to parse a solution file and programmatically add a custom assembly reference to each project in the solution.

我尝试使用以下代码片段来做同样的事情:

I tried using the following code snippet to do the same:

//The name of the DLL is customLib.dll var reference = MetadataReference.CreateAssemblyReference("customLib"); project = project.AddMetadataReference(reference);

但是,它在创建 MetadataReference 时遇到 FileNotFoundException.

However, it encounters a FileNotFoundException while creating the MetadataReference.

所以,我的问题是:如何指定 Roslyn 需要检查指定 dll 的路径?

谢谢.

推荐答案

MetadataReference.CreateAssemblyReference 用于获取对 GAC 中程序集的引用.试试这个:

MetadataReference.CreateAssemblyReference is used to get references to assemblies in the GAC. Try this:

project = project.AddMetadataReference(new MetadataFileReference("<path>"));

更多推荐

如何以编程方式向项目添加程序集引用?

本文发布于:2023-11-09 23:12:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   程序   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!