1

I have a C# project called TestProduct.sln Unfortunately depending on the user the program has to react diffently at one point. How can i tell the program for which user it is compiled? Do i have to use DefineConstants while building like:

msbuild /p:DefineConstants=USER1 TestProduct.sln

and within my code:

#if USER1
    // do something USER1 specific
#endif

Or do i have to do something completely different to archieve the wanted behavior?

Thanks in advance for your help.

Edit: Sorry for expressing myself wrong, i have to clarify the situation. Users was the wrong wording i had to call it customers. Foreach customer there is a batch file which starts the msbuild command. And within the msbuild command i want to tell built binary for which customer it will be provided.

Action Heinz
  • 722
  • 10
  • 23
  • You can use $(USERNAME) to read the USERNAME environment variable. – Leo Chapiro Nov 02 '16 at 14:44
  • @Action Heinz, could you get useful information from dude and cristallo's suggestions? I agree with them, use the Environment variable would be a good path for this issue. Not the same issue, but a good reference: http://stackoverflow.com/questions/11690574/is-there-a-way-to-make-user-specific-pre-post-build-events-in-visual-studio-proj – Jack Zhai Nov 14 '16 at 12:31

1 Answers1

0

I had a similar problem in the past and I addressed it in this way.

I get username using the $(USERNAME) environment variable. Then I have multiple batch file named USERNAME.doit.bat and in post build event VS runs $(USERNAME).doit.bat. In this way each user has its own file batch for the custom post build operations.

cristallo
  • 1,951
  • 2
  • 25
  • 42