Create MSBuild custom task to modify C# files before compilation
Hi,
I need to rewrite some properties and function calls for interop, and would love to do that in a MSBuild Task.
How can I overwrite the Compile item group with my modified files?
19 Replies
you should absolutely not even try to do this. what is your concrete use case, can you share a little bit more about it?
in theory there are source generators, which you should prefer for adding source files to your compilation automatically, but this doesn't involve modifying files
I'm integrating C# into a game engine, and need the user written C# properties to fetch the value in memory from C++. I could use Mono.Cecil to weave the instructions, but it's very cumbersome
Source generators would not work for my use case
why not?
that sounds like exactly the perfect use case for source generators
You can't modify the code in place, as you said. I need to modify the file
you do not need to modify the file. why would you?
what i believe you're looking for here is partial properties, yes?
For functions it wouldn't work, RPC calls needs to be rewritten
user code:
generated code:
would this not be viable for you?
(same thing can be done for methods)
I don't see how this can be achieved with source generators
interceptors would be a better fit, but unfortunately i don't know the current state of them
i can't think of a good solution here that doesn't make some kind of compromise
which is one kind of compromise
i would seriously highly recommend against modifying source files, it feels like asking for trouble
I'm not modifying the original source file
i understand what you're doing, it's still bad
you can for example do
That's not gonna cut it. I'll research further
how so?
Not how I want the syntax to be for this scripting layer of the engine
that's a pretty arbitrary barrier
It's still not how I want it 😅
So I'll research further, thank you guys for the help though! 😄
Yea, been thinking of something similar like this.
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
If you want to make an incremental source generator, please make sure to read through both the design document and the cookbook before starting.
another partial?