【问题标题】:Adding resource in Codedom compiled file VB.NET在 Codedom 编译文件 VB.NET 中添加资源
【发布时间】:2016-11-24 12:37:18
【问题描述】:

我曾尝试寻找解决方案,但惨遭失败。谁能指出我正确的方向来解决问题?参考Codedom:https://msdn.microsoft.com/en-us/library/y2k85ax6(v=vs.110).aspx

我正在尝试使用以下方法添加资源:

Parameters.EmbeddedResources.Add(Directory.GetCurrentDirectory & "\HTML.txt")
Parameters.EmbeddedResources.Add(Directory.GetCurrentDirectory & "\logo.png")

但我无法使用以下方法从外部源访问它们:

 Dim content As String = My.Resources.HTML
 Dim logo As Image = My.Resources.logo

这是错误:

'Resource' is not memeber of 'My'.
'Resource' is not memeber of 'My'.

【问题讨论】:

标签: vb.net resources codedom


【解决方案1】:

这是我解决问题的方法:

Compiler.vb

Using rw As New ResourceWriter(".\Library.resources")
   rw.AddResource("HTML.txt", My.Resources.HTML)
   rw.Generate()
   rw.Close()
End Using
Parameters.EmbeddedResources.Add(".\Library.resources")

source.txt

Dim rm As New ResourceManager("Library", GetType(NameSpace).Assembly)
Dim SomeString As String = rm.GetString("HTML.txt")

【讨论】:

  • 这对我不起作用,在我的情况下,资源不是文本文件,它们是 dll 文件,我需要使用函数创建它们:File.WriteAllBytes()... .,你有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多