Search code examples
c#command-line

Embed XML file in C# assembly - command line


The common method for embedding XML files in a C# executable is to simply add it to the project in Visual Studio, then change its "Build Action" property to "Embedded Resource."

This works very well in Visual Studio, but how can the same result be accomplished with only the command line?


Solution

  • Turns out the solution was to use the /res argument when compiling, with this syntax:

    /res:MyFile.xml,MyNamespace.MyFile.xml
    

    Where MyFile.xml is the file in the source directory, and MyNamepace.MyFile.xml is the name that's used when calling GetManifestResourceStream().