1

我有一個PCL定位ASP.NET核心& .NET Framework 4.6。如何從PCL訪問嵌入式資源定位ASP.NET CORE和.NET Framework 4.6

在PCL的根目錄中,我添加了PCLResource.txt並將其標記爲Build Action> Embedded Resource。

發佈到的NuGet,從安裝的NuGet我的消費者的WinForm應用(4.6.2)

調用PCL.TestMethod()作品。然而,

string[] asm = Assembly.GetExecutingAssembly().GetManifestResourceNames(); 

而且

var assembly = GetType().GetTypeInfo().Assembly; 
string[] resources = assembly.GetManifestResourceNames(); 

結果:

  • PCLConsumerApp.Form1.resources
  • PCLConsumerApp.Properties.Resources.resources

而且

Stream stream = assembly.GetManifestResourceStream(string.Format("PCL.PCLResrouce.txt")); 

結果null

使用dotPeek,我可以看到PCLResrouce.txt的DLL。 dotPeek of PCL Resources

如何作爲用戶訪問Embedded Resource文本文件?

我用以下資源:

我意識到我拼寫錯誤的資源:/而不是多數民衆贊成這個問題。

回答

0

我的問題是我沒有得到PCL組件。

解決方案:

var assembly = Assembly.GetAssembly(typeof(StaticPCLClass)); 

我不一定有這個類的工作時,我需要的資源,但是這可以讓我獲得了大會。 現在我能夠撥打:

Stream stream = assembly.GetManifestResourceStream(string.Format("PCL.PCLResrouce.txt")); 

here二手幫助。