You can do something like this using ConditionalAttribute
This is how Debug.WriteLine() present or not present depending on the presence of the "DEBUG" character.
You can define your own name for the conditional character that you use to control the presence or absence of the code.
Then you can put this symbol in the list in the "Conditional compilation symbols" options on the "Build" tab of the project for the project in which you want to get the code.
This does not allow you, unfortunately, to have part of "other code", and also applies only to all methods.
source share