One of the things that I like about tools like MSBuild (and NAnt for that matter) is that there is a community that builds up around them providing useful extensions. One such extension that I stumbled across was an MSBuild task from the Microsoft SDC which supports the setting (and getting) of environment variables.

More than anything, this post is just to serve as a reminder to me that this task exists so that I don’t try and create another one down the track.

One Response to “How To: Set and Environment Variable in MSBuild”


  1. Of course, in MSBuild, there is no need to have a special task to retrieve environment variable values. Just reference them as you would reference any property in an MSBuild script:

    Assuming the USERNAME environment variable is already set on your system, nothing needs to be defined/set within the MSBuild script.


Leave a Reply