Hi,
The following link contains an example:
CompilerParameters.EmbeddedResources Property
http://msdn2.microsoft.com/en-us/lib...resources.aspx
To create the resource file you can write it to a temporary file on disk for
use with the CodeDOM:
..NET Framework Class Library
ResourceWriter Class
http://msdn2.microsoft.com/en-us/library/system.resources.resourcewriter(VS.80).aspx
Here's an example that I've derived based on the links above (your
serialized xml can be a byte[] or string here):
string temp = Path.Combine(Path.GetTempPath(),
Path.GetTempFileName());
try
{
using (FileStream stream = new FileStream(temp))
// Unfortunately, the EmbeddedResources property is a
// StringCollection and accepts only file paths, not resource
// streams, so MemoryStream can't be used here
{
using (ResourceWriter writer = new ResourceWriter(stream))
{
// your xml can be byte[] or a string
writer.AddResource("name", yourXml);
writer.AddResource("name2", yourXml2);
}
}
CompilerParameters cp = new CompilerParameters();
// provider is an instance of CodeDomProvider
if (provider.Supports(GeneratorSupport.Resources))
{
cp.EmbeddedResources.Add(temp);
}
...
CompilerResults cr =
provider.CompileAssemblyFromFile(cp, sourceFile);
...
}
finally
{
File.Delete(temp);
}
I haven't tested the code myself so beware
--
Dave Sexton
http://davesexton.com/blog
"CodeLeon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you for your reply. It is much appreciated. So, how would I do
> this programatically, usang an ICodeCompiler or similar class? How
> would I use a simple (ie, serialized) XML file?
>
> Thanks again!
>
> Dave Sexton wrote:
>> Hi,
>>
>> When you compile the assembly with the C# compiler use a /resource switch
>> for each resource that you want to embed:
>>
>> C# Language Reference
>> /resource (Embed Resource File to Output) (C# Compiler Options)
>> http://msdn2.microsoft.com/en-us/library/c0tyye07(VS.80).aspx
>>
>> You can use the resgen tool to create binary resources from an xml
>> resource
>> file (.resx) that you can supply to the C# compiler:
>>
>> .NET Framework Tools
>> Resource File Generator (Resgen.exe)
>> http://msdn2.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx
>>
>> --
>> Dave Sexton
>> http://davesexton.com/blog
>>
>> "CodeLeon" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hi, All. I am creating a setup program. The way it works is that the
>> > user creates their setup info, my program generates the C# code for a
>> > setup executable, embeds the xml file containing the info for the
>> > setup, and compiles the whole thing into one EXE. How do i embed
>> > resources, and access them, into that assembly?
>> >
>