【问题标题】:MSBuild parse item metadataMSBuild 解析项目元数据
【发布时间】:2011-01-05 16:39:34
【问题描述】:

是否可以修改项目组中的每个项目?例如,给定这个项目:

<_CustomAreas Include="..\My.Project.*\Areas\**\*.*" Condition="'$(AppBuildFolder)' == ''" />

我想删除 "..\My.Product.* 部分。基本上我们有包含 MVC 区域的单独项目,并且在打包/部署 (MSDeploy) 中我们希望将它们复制到主项目中。这里是使用组:

<FilesForPackagingFromProject Include="%(_CustomAreas.Identity)">
    <DestinationRelativePath>Areas\%(relativedir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>

$(relativedir) 以“..\My.Project.Plugin1\Areas**.”的形式出现,并以 ZipFileRoot\My.Project.Plugin1\Areas 的形式出现在包中(.. 退出硬编码的区域,然后它只是为插件创建文件夹\区域),我希望它实际上都以ZipFileRoot\Areas结尾。

谢谢 安迪

【问题讨论】:

    标签: msbuild .net-4.0 msdeploy


    【解决方案1】:

    RegexReplace(凭据:guest/guest)任务应该能够匹配 \My.Product.* 并替换为空字符串。

    这样的东西应该可以工作:(未经测试,需要验证转义)

    <RegexReplace Input="%(_CustomAreas)" Expression="\\My\.Product\..*" Replacement="" Count="-1">
        <Output ItemName="_CustomAreas" TaskParameter="Output" />
    </RegexReplace>
    

    MSBuild Community Tasks 启动和运行需要一点工作,但其中有足够的好东西让我觉得值得付出努力。

    【讨论】:

      【解决方案2】:

      在 MsBuild 4.0 中,您可以直接在脚本中使用 String 方法(或使用内联任务)。使用此选项,您可以编辑 relativedir 以删除 My.Project.* 部分。

      您可以在本文中查看示例:http://sedodream.com/2010/03/07/MSBuild40PropertyFunctionsPart1.aspx

      【讨论】:

      • 我也喜欢这个答案,但我不清楚如何对 ItemGroup 进行操作。
      【解决方案3】:

      ItemGroups 中的项目可以有一个 Exclude 属性,允许您指定要忽略的项目。

      【讨论】:

      • 这不是我要求做的。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多