How do I programmatically add an assembly reference to a project?

自闭症网瘾萝莉.ら 提交于 2019-12-22 04:55:11

问题


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);

However, it encounters a FileNotFoundException while creating the MetadataReference.

So, my question is : How do I specify the path at which Roslyn needs to check for the specified dll?

Thanks.


回答1:


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

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


来源:https://stackoverflow.com/questions/13287123/how-do-i-programmatically-add-an-assembly-reference-to-a-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!