簡體   English   中英

如何以編程方式將程序集引用添加到項目?

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

我一直在嘗試使用Roslyn來解析解決方案文件,並以編程方式為解決方案中的每個項目添加自定義程序集引用。

我嘗試使用以下代碼片段來執行相同的操作:

//The name of the DLL is customLib.dll
var reference = MetadataReference.CreateAssemblyReference("customLib");
project = project.AddMetadataReference(reference);

但是,它在創建MetadataReference時遇到FileNotFoundException。

所以,我的問題是: 如何指定Roslyn需要檢查指定dll的路徑

謝謝。

MetadataReference.CreateAssemblyReference用於獲取GAC中程序集的引用。 嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM