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.
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