Codedom and resources files

  • Thread starter Thread starter Marc R.
  • Start date Start date
M

Marc R.

Hello,

I built a code generator that builds an assembly composed of several
classes. These classes are written in VB.NET. But these classes must use an
XML file. It contains some information to configure the behavior of classes
in the assembly. So I want to add this XML file as a resource for this
assembly. I use Codedom to generate my assembly. I want someone tells me how
or point me to a Web site that explains how to add a file as a resource
during compilation of the assembly.

Thank you
 
Hello,

I built a code generator that builds an assembly composed of several
classes. These classes are written in VB.NET. But these classes must use an
XML file. It contains some information to configure the behavior of classes
in the assembly. So I want to add this XML file as a resource for this
assembly. I use Codedom to generate my assembly. I want someone tells me how
or point me to a Web site that explains how to add a file as a resource
during compilation of the assembly.

Thank you

You need to pass a CompilerParameters object to your provider when you
compile the code. The CompilerParameters object has a property, named
EmbeddedResources. This is a string collection, that you add the path's
to any files you want added to your assembly as resources.
 
I have found! here is the solution that I used
Ressources is a List(Of String). It has my Document.InnerXml as one element
of the collection of strings.

Dim temp As String = Path.Combine(Path.GetTempPath,
Path.GetTempFileName)

If Ressources.Count > 0 Then
Dim stream As New FileStream(temp, FileMode.Create)
Dim writer As ResourceWriter = New ResourceWriter(stream)
Dim i As Integer = 0

For Each Ressource As String In Ressources
writer.AddResource("name" + i.ToString, Ressource)

i += 1

Next

writer.Close()

compilerParameters.EmbeddedResources.Add(temp)

End If
 
Back
Top