Copying files in Windows is very fast, copying memory to memory thanks to the file system cache. This happens especially in the assembly, because the files have just been created, so their data is always present in the cache. Actual writing to disk occurs no later than when the cache manager lazily writes file data to disk. Which runs in the background and cannot slow down the build. The only time a copy of a file is slow is when the file system cache is full and must wait for a slow disk to write to make more space.
Copying the same file more than once, even if it was not created by the assembly, is similarly fast. You pay only for reading the file for the first time. After that, any subsequent copy always uses the data of the cached file.
There is no reasonable scenario where a .NET solution can fill the cache and increase it on a machine with 8 gigabytes of RAM. The cache must be at least 2 gigabytes. Writing a .NET solution that generates 2 gigabytes of code and resources is not a reasonable option.
You are trying to solve the wrong problem.
source share