Search code examples
vb.netresourcescodedom

Adding resource in Codedom compiled file VB.NET


I have tried searching for a solution but failed miserably. Can anyone please point me in the right direction to a solution? Reference to Codedom: https://msdn.microsoft.com/en-us/library/y2k85ax6(v=vs.110).aspx

I am trying to add resource using:

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

But I can't access them from external source using:

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

This is the error:

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

Solution

  • Here's how I solved the problem:

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