0
<Target Name="ProtobufCompile"
        Inputs="@(ProtocCompile)"
        Outputs="$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))%(ProtocCompile.Filename).cs">
  <PropertyGroup>
    <protooutdir>$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))</protooutdir>
  </PropertyGroup>
  <Message Text="%(ProtocCompile.Filename)%(ProtocCompile.Extension)" Importance="high" />
  <MakeDir Directories="$(protooutdir)" />
  <Exec Command="$(ProtobufCompiler) --protoc_dir=${PROTOBUF_PROTOC_EXECUTABLE}/.. --proto_path=%(ProtocCompile.RootDir)%(ProtocCompile.Directory) -output_directory=$(protooutdir) %(ProtocCompile.FullPath)" />
</Target>
<!-- set Intputs and Outputs -->
<Target Name="ProtobufCSharpCompile"
        DependsOnTargets="ProtobufCompile">
  <CreateItem Include="$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))%(ProtocCompile.Filename).cs">
    <Output TaskParameter="Include" ItemName="Compile"/>
  </CreateItem>
</Target>
<Target Name="ProtobufClean"
        BeforeTargets="Clean">
  <Delete Files="$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))%(ProtocCompile.Filename).cs" />
</Target>

这是一段目标文件。如何简化这段代码?如何减少以下字符串的重复?

$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))
4

1 回答 1

1

由于您已经为该值指定了一个属性,如下所示:

  <PropertyGroup>
  <protooutdir>$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))</protooutdir>
  </PropertyGroup>

您可以使用属性$(protooutdir)替换对该字符串的引用,如下所示:

<CreateItem Include="$(protooutdir)%(ProtocCompile.Filename).cs">

<Delete Files="$(protooutdir)%(ProtocCompile.Filename).cs" />
于 2012-04-17T14:00:24.377 回答