Is there a way in Visual Studio (any version) to embed the content of a file in another file upon compiling? For instance, if one wanted to embed an xml file in a vb code file how would it best be done?
If you don't mind it actually being in your code, you can use an XML Literal.
I was about to mention using the #include
preprocessor directive (for C and C++), but then you mentioned VB. I don't think VB supports such a thing.
I have no idea on how to go about doing this. But the first thought that came to my mind was that of Build Providers (the thing that generate classes from xml file in case of an ORM).
I searched & found 1 more thing called Custom Tools, which can act on a file existing in your solution and can be used to generate code file.
See if this link helps at all - http://www.drewnoakes.com/snippets/WritingACustomCodeGeneratorToolForVisualStudio/
Have a look at Resources. You can create a string resource that has your xml. This is then compiled into your application image.
Brian beat me about the embeded resource as I was looking for the resource URL :)
Add the file to your project, right click on the file and select its properties. Under "Build Action" change it to "Embedded Resource". Now when you compile the file is automatically embedded as a resource.
Here is an example showing how to access an embedded bitmap resource.
What I've done in the past is write a simple .bat file that concatenates 3 different sources into a final source file that actually gets compiled. The .bat file is run as part of the Pre-Build event.
Project
- SourceTop.vb
- Source.xml
- SourceBottom.vb
All of these files have a Build Action of "None"
- Merged.vb
merge.bat
type SourceTop.vb > Merged.vb type Source.xml >> Merged.vb type SourceBottom.vb >> Merged.vb