Removed: Rule 3.
There is Windows 10 Sandbox amd the now-free Sandboxie tool if you want to run a program in a sandboxed environment. It’s probably more what you need than compiling something. Especially if its an existing program. And this isn’t csharp specific. Interesting though.

Sandboxie is great. But I wanna get rid of third party app as far as it could be done in naked Windows. Btw Windows 10 sandbox = Hyper-V virtual machine. I don’t need a VM, I need so called “virtual file system layer” like Sandboxie having Windows 10 only
This is background about app containers.
I also found This SO question, which links to This C++ app that does what you need.
IDK how to run it? Ther’s no executables
C# devs
null reference exceptions

source