Can the C # compiler insert constant values โโthat are automatically incremented with each use at compile time?
No, there is nothing in this language.
There are some cumbersome hacks that will let you keep track of the caller's file / line / member and automatically increment it (if you're using C # 5), but it really won't.
There are tool-based approaches to this that will transform your source code, but I'll try to take a step back and look at your actual requirements and intentions (which we don't know at the moment) and try to find a solution within the language if you can.
source to share
One such thing that does this is the build number of the build version. If you install build version eg. 1.2.*
, the last two digits will be changed with every build. You can easily read this in your code - it is not a constant, but if you expose it via a static property it might work fine.
If that's not enough, just create a build target. It shouldn't be difficult to maintain a nearly empty C # file with a fixed structure that you can modify prior to each build.
source to share