I want to generate a serialization assembly or .cs file to serialize my types using XmlAttributeOverrides, and then reference this assembly/.cs file in my project directly rather than use XmlSerializer to perform xml serialization/deserialization. This is because the serialization uses XmlAttributeOverrides and when you create an XmlSerializer with overrides it doesn't look for an existing assembly but will always re-generate one (reference). My program runs in an environment where it's not possible to run csc.exe, therefore my I cannot generate a serialization assembly at runtime.
To be clear, I can't just use sgen.exe because that only generates assemblies that perform the default xml serialization/deserialization. If you create an XmlSerializer and pass it XmlAttributeOverrides in the constructor then Serialize() and Deserialize() do NOT use the assembly generated by sgen.exe, therefore sgen.exe seems of no use to me. When using overrides XmlSerializer will always generate a new assembly.
So, is there a way I can call XmlSerializer or other classes and get it to create a .cs file or dll that I can include in my project? I'd like to automate this process if possible so I don't need to make manual changes whenever I change my types that are being serialized. I can't use sgen.exe /k because that only generates the default XmlSerializer for a type instead of the one I need which uses overrides. Is there another way to generate or capture the .cs file that's created by XmlSerializer?
(I have a related question here that's the root of this one)