locked
Do the environment variables in a batch script persist during build? RRS feed

Answers

  • Hi,

    I think this is related to Child Process Inheritance.  

    For example, set.bat is used to set the environmet variable A and get.bat is used to get A. The original value of A is 0.

    When MSBuild runs, System will create the environment variables for MSBuild process, the value of A is 0.

    When MSBuild uses Exec Task to excute set.bat, the task will create a new process and the value of A is set to 1  in the process. But the value in MSBuild process does not change.

    A child process inherits the environment variables of its parent process by default.

    When MSBuild  uses Exec Task to excute get.bat, so the new process has the same environment with MSBuild process, which means A is 0.

     

     If you want to use a property from previous Target, a way is to create a Task with output properties.


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Tuesday, August 10, 2010 9:22 AM
    Moderator

All replies

  • So it appears that the answer to my qusetion is "No" as my build just failed again.
    Monday, August 9, 2010 2:29 PM
  • Hi,

    I think this is related to Child Process Inheritance.  

    For example, set.bat is used to set the environmet variable A and get.bat is used to get A. The original value of A is 0.

    When MSBuild runs, System will create the environment variables for MSBuild process, the value of A is 0.

    When MSBuild uses Exec Task to excute set.bat, the task will create a new process and the value of A is set to 1  in the process. But the value in MSBuild process does not change.

    A child process inherits the environment variables of its parent process by default.

    When MSBuild  uses Exec Task to excute get.bat, so the new process has the same environment with MSBuild process, which means A is 0.

     

     If you want to use a property from previous Target, a way is to create a Task with output properties.


    Best regards,
    Ruiz
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Tuesday, August 10, 2010 9:22 AM
    Moderator