Codedom and resources files

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
 
T

Tom Shelton

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.
 
M

Marc R.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top