简体   繁体   中英

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?

MSBuild is more generic tool to build complex project that have more than cople .CS files. MSBuild is command line equivalent of building .CSProj in Visual Studio.

To build solution with MSBuild:

  • launch "Visual Studio Command Prompt" (or run command file that sets environment VS variables)
  • check if msbuild is correctly in PATH: `msbuild /?"
  • specify .Csproj as argument to build it : msbuild MyProject.csproj .

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM