简体   繁体   中英

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

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 : ?

Thanks.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM