Search code examples
c#visual-studioembedded-resourcepre-build-event

How to add source file (.cs) to resources (.resx) in a pre-build event?


Is it simple or even possible?

Why: Following my other question and using this approach, now I would like to simply embed the source file to the resources so I can copy it to the temp folder while the application is running - and keep the application as a single file.

I assume using a pre-build event is the best way to do this. If so, how would it be done?

EDIT: I'm asking about adding it before building because I also assume it won't be automatically updated if I add it manually once and then change the code after.


Solution

  • Turns out I don't need to (re)add the source file each time I build the solution!

    When I add it manually once it becomes a "Text" file on resources - and I can easily access it as a string using Properties.Resources.SourceCode (having the file named "SourceCode.cs"). And yes, it is updated automatically since the resource property "Persistence": the file is linked at compile time.