2011-09-20 23 views
0

它是MSBuild 4.0属性函数的限制,我无法从内部访问属性?MSBuild 4.0属性函数不能访问它们内部的属性

这里是工作的很好的例子:

<PropertyGroup> 
    <PartialConnection>$(TargetConnectionString.Substring(0 + 12))</PartialConnection> 
</PropertyGroup> 

这里是能源部鼻涕工作的另一个例子。 (I与另一属性替换0

<PropertyGroup> 
    <LocationOfDataSource>$(TargetConnectionString.IndexOf("Data Source="))</LocationOfDataSource> 
</PropertyGroup> 
<Message Importance="high" Text="Location is = $(LocationOfDataSource)"/> 
<PropertyGroup> 
    <PartialConnection>$(TargetConnectionString.Substring($(LocationOfDataSource) + 12))</PartialConnection> 
</PropertyGroup> 

此输出

位置为= 0
错误MSB4184:表述 “” 数据源= MySQLServer;集成安全性= TRUE;池=假“.Substring(0 + 12)”不能被评估。输入字符串的格式不正确。

我把输出和插入控制台应用程序,它工作得很好。我尝试过几种变化,当我将属性放入属性函数内时,它们总是失败。 (我甚至尝试在我的房产功能中两次访问相同的属性,但也失败了。)

属性函数不支持访问属性吗?

回答

2

我想我的问题是假设数学是免费的。

我需要做这样的事情:

<PropertyGroup> 
    <LocationOfDataSource>$(TargetConnectionString.IndexOf("Data Source="))</LocationOfDataSource> 
    <LenthOfDataSourceString>12</LenthOfDataSourceString> 
    <LocationOfEndOfDataSourceString>$([MSBuild]::Add($(LocationOfDataSource), $(LenthOfDataSourceString)))</LocationOfEndOfDataSourceString> 
    <PartialConnectionString>$(TargetConnectionString.Substring($(LocationOfEndOfDataSourceString)))</PartialConnectionString> 
</PropertyGroup> 

注意,我使用Add($(财产),$(物业))在这个版本中加入。

它似乎现在工作。

+1

打我吧:正准备发布! http://msdn.microsoft.com/en-us/library/dd633440.aspx –