本文介绍了如何以编程方式向项目添加程序集引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试使用 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>"));更多推荐
如何以编程方式向项目添加程序集引用?
发布评论