How to programmatically add an assembly link for a project?

I am trying to use Roslyn to analyze a solution file and programmatically add an assembly reference for 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, when creating a MetadataReference, a FileNotFoundException is thrown.

So my question is: How to specify the path where Roslyn should check the specified DLL ?

Thanks.

+7
source share
1 answer

MetadataReference.CreateAssemblyReference used to get assembly references in the GAC. Try the following:

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

All Articles