问题
I have an XML generated at runtime. I need to embed this XML content into an assembly using CodeDOM. The XML will be accessed later from the assembly.
How can I embed XML into assembly ? Should I include the XML as EmbeddedResources in the assembly ?
Thanks
回答1:
Yes, for example, with the EmbeddedResources
property. For example:
Assembly a1 = typeof(MyClass).Assembly;
System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters();
cp.ReferencedAssemblies.Add(a1.Location); // for example
cp.GenerateInMemory = false;
cp.GenerateExecutable = true;
cp.IncludeDebugInformation = false;
cp.CompilerOptions = "";
cp.CompilerOptions += String.Format("/win32icon:\"{0}\"", nameOfIconFile);
cp.CompilerOptions += " /target:winexe";
cp.EmbeddedResources.Add(xmlFileName);
var csharp = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.CompilerResults cr = csharp.CompileAssemblyFromSource(cp, LiteralSource);
The xml needs to be available in a file, in order to embed it as a resource.
来源:https://stackoverflow.com/questions/5920960/embedding-xml-in-assembly-using-codedom