MSBuild bug with CreateProperty and CallTarget

After banging my head against the wall for a short period of time I came across Sayed Ibrahim Hashimi’s post about a bug in the RTM of MSBuild.

Basically if you call CreateProperty and CallTarget in the same Target, your new property will not be globally available to other targets.  You must move the CreateProperty into a Target by itself.

The funny thing is that Microsoft marked his bug as resolved and said  “Good suggestion -- we will look into this for a future version.”  Not sure how that resolves the issue…

This will not work:

   45   <Target Name="Main">

   46     <CreateProperty Value="Hello World!">

   47       <Output TaskParameter="Value" PropertyName="MyString" />

   48     </CreateProperty>   

   49     <CallTarget Targets="OutputString" />

   50   </Target>

   51 

   52   <Target Name="OutputString">

   53     <Message Text="MyString: $(MyString)"  />

   54   </Target>

And this will work:

   45   <Target Name="Main">

   46     <CallTarget Targets="SetString" /> 

   47     <CallTarget Targets="OutputString" />

   48   </Target>

   49 

   50   <Target Name="SetString">

   51     <CreateProperty Value="Hello World!">

   52       <Output TaskParameter="Value" PropertyName="MyString" />

   53     </CreateProperty>   

   54   </Target>

   55 

   56   <Target Name="OutputString">

   57     <Message Text="MyString: $(MyString)"  />

   58   </Target>



 

Published Monday, March 20, 2006 2:21 PM by dotnetboy2003
Filed under:

Comments

# re: MSBuild bug with CreateProperty and CallTarget

This article was a great help for me!!!

Monday, August 18, 2008 9:19 AM by tom

# re: MSBuild bug with CreateProperty and CallTarget

Thank you so much!

I was getting very confused about why CreateProperty only worked in half of my scripts.

Wednesday, August 20, 2008 12:03 AM by Romain

# re: MSBuild bug with CreateProperty and CallTarget

Thanks A HELLUVA LOT!!!

Thursday, November 27, 2008 12:30 PM by Dmitry

# re: MSBuild bug with CreateProperty and CallTarget

i have similar issue but i am using the dependent tasks property, i will check if this is also the same

Saturday, January 30, 2010 1:34 PM by Ran Davidovitz

# re: MSBuild bug with CreateProperty and CallTarget

Thanks, saved a lot of pain.

Friday, October 29, 2010 11:14 AM by Si