0

我无法从内部访问属性是 MSBuild 4.0 属性函数的限制吗?

这是一个可以正常工作的示例:

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

这是另一个不起作用的例子。(我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:无法评估表达式“”Data Source=MySQLServer;Integrated Security=True;Pooling=False”.Substring(0 + 12)”。输入字符串的格式不正确。

我获取了输出并插入了一个控制台应用程序,它工作得很好。我尝试了几种变体,当我将属性放在属性函数中时,它们总是失败。(我什至尝试在我的属性函数中访问相同的属性两次,但也失败了。)

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

4

1 回答 1

2

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

我需要做这样的事情:

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

请注意,我在此版本中使用 Add($(Property), $(Property)) 添加。

它现在似乎正在工作。

于 2011-09-20T21:35:50.410 回答