Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

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.

like image 302
jithinpt Avatar asked Nov 08 '12 10:11

jithinpt


1 Answers

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

project = project.AddMetadataReference(new MetadataFileReference("<path>"));
like image 60
Jason Malinowski Avatar answered Sep 19 '22 07:09

Jason Malinowski