views:

72

answers:

1

I'm pretty new to MSBuild, so I might be doing something obviously-wrong, but a colleague of mine who's worked with MSBuild a lot can't see any error, so I figured I'd post here and see if anyone else can see it.

I'm converting an old batch file that we used to call ant to MSBuild tasks (because we want to call it from MSBuild) and the environment variables always expand to )for reasons we don't understand.

I have a property group that includes

<PropertyGroup>
  <EnvJavaHome>
    $([System.Environment]::GetEnvironmentVariable("JAVA_HOME"))
  </EnvJavaHome>
  <!-- ... -->
</PropertyGroup>

(line breaks added for legibility). Now the MSBuild Property Functions reference suggests I'm calling System.Environment.GetEnvironmentVariable correctly, but I always get a value of ). The code works perfectly well when I hardcode the value, however.

What obvious thing am I missing? :o)

+4  A: 

If it's an env variable, you should be able to just use it like $(JAVA_HOME) as in <EnvJavaHome>$(JAVA_HOME)</EnvJavaHome> , see e.g. use http://msdn.microsoft.com/en-us/library/ms171459(v=VS.100).aspx

(Check that the environment variable actually exists though, echo %JAVA_HOME% in a command window)

nos
I just discovered exactly the same thing and figured I should hit reload before posting the fact.Thank you! :o)
Owen Blacker