首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何简化MSBuild-targets?

如何简化MSBuild-targets?
EN

Stack Overflow用户
提问于 2012-04-17 20:31:25
回答 1查看 496关注 0票数 0
代码语言:javascript
复制
<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>

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

代码语言:javascript
复制
$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-17 22:00:24

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

代码语言:javascript
复制
  <PropertyGroup>
  <protooutdir>$(IntermediateOutputPath)$([System.Text.RegularExpressions.Regex]::Replace('%(ProtocCompile.RelativeDir)','\.\.[/\\]',''))</protooutdir>
  </PropertyGroup>

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

代码语言:javascript
复制
<CreateItem Include="$(protooutdir)%(ProtocCompile.Filename).cs">

代码语言:javascript
复制
<Delete Files="$(protooutdir)%(ProtocCompile.Filename).cs" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10191307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档