I have a few C# (*.cs) files in my project that need to be included in compilation as well as distributed as source code along with the application (the application itself is not open-source).
Currently, I have the Build Action
for such files set to C# Compiler
, and I then use a Post-build event
to copy those files to the application directory. This is far from ideal in my scenario since these files are frequently. In any case, the Post-build
depend on referencing the VS solution/project path to access the *.cs
files.
There seems to be no way to associate a single file with multiple Build Action
s. The objective is to have these files compiled and also be available as plain C# text in the app's Resource Manifest
.
I am sure many would ask why I want to do this. Suffice it to say, this is a complex code-generation scenario where the app itself consumes these files and then presents them to end-users to consume as a template (plain text C# code). I thought about decompilation but that is overkill and would not preserve code formatting.
Any advice would be appreciated.
UPDATE: A simpler way to understand the objective. I need to edit the the file at compile-time with full solution-wide Intellisense context AND somehow access the same source code at runtime.
I cannot believe that I missed this!
I was concentrating on the Build Action
and did not realize that project items which are set to compile can also be copied to the output directory.