-1

I have my big project that takes XML configuration files as inputs. I have XSD schema for these XMLs. XSD is placed in Visual Studio as any other C# code files. I want to import the schema into exe so no one can change it and with it change the program itself.

I want to address XSD schema from the code, like this:

XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("confcheck", MyProject.Configuration.ConfSchema );

where Configuration is folder with schema between my code files

Jara M
  • 125
  • 7
  • As embedded-resources? – Dai May 21 '18 at 19:06
  • 4
    `I want to import the schema into exe so no one can change it and with it change the program itself.` If the only reason is this, than don't bother... It can be modified.... – Eser May 21 '18 at 19:06
  • Yes, ideally as embedded resources. – Jara M May 21 '18 at 19:16
  • 1
    Take a look at this answer, it describes how to read a text file as an embedded resource. https://stackoverflow.com/a/49203966/9365244 – JayV May 21 '18 at 19:16
  • @Eser You can sign the executable, so that if it's changed it's force to be unsigned. If the goal is to prevent someone from changing the program to something malicious and then redistributing it to others without them realizing it has been changed, you can address it (by telling people to not trust unsigned versions of your executable). What you can't defend against is someone changing the program and then running it themselves, because they can just ignore the fact that their changed version is unsigned. – Servy May 21 '18 at 19:27
  • @Servy Jara's case is in your last sentense, and What I said was that... – Eser May 21 '18 at 19:44
  • @Eser You don't know which case they're actually worried about. That is unless you know something not in the question. – Servy May 21 '18 at 19:45

1 Answers1

1

Generally speaking I would recommend put the configuration in the config file that comes with the project (you can create and load custom config sections from that file), but there are several routes you could take do do what you describe - all of which involve the build action (right click object then properties):

enter image description here

  1. Change the build action to embedded resource then go here
  2. Change the build action to content and set copy to output directory as "always" - then, you can programmatically open it up and serialize it at run-time (make sure to build the path in your code relative to the executing directory)

keep in mind that if you make it content and it gets copied to the output folder, anyone with access to the installation directory will be able to open those up and modify them - embedded resource is not totally 100% tamper proof either, but more so for a novice.

Ben
  • 1,032
  • 8
  • 18
  • This works. Just `set copy to output directory as "always"` is not necessary. It copies those embedded files in exe file folder. But this file is actually not used. Anyway thanks for solution. – Jara M May 21 '18 at 20:07