【问题标题】:Checking if project has a specific target in MSBuild检查项目是否在 MSBuild 中具有特定目标
【发布时间】:2009-11-16 12:16:11
【问题描述】:

我的一些 .csproj 项目文件具有特殊的目标“AssembleJS”,它将项目中包含的所有 .js 文件合并到一个大文件中(即 webcontrols.csproj 的目标“AssembleJS”与输出“webcontrols.js”)。

所以如果我有项目 parts.csproj

  1. 具有目标 AssembleJS
  2. 参考项目 webcontrols.csproj
  3. 参考实用程序 project utils.csproj 没有任何 JavaScript 并且没有 AssembleJS 目标。

我希望parts.csproj 的目标AssembleJS 在webcontrols.csproj 中执行AssembleJS(与MSBuild 与标准Build 目标一起使用)。

有点像

<MSBuild Project="@ReferencedProjects" Targets="AssembleJS"/> 

不起作用,因为 utils.csproj 没有目标 AssembleJS。

有没有办法根据项目是否有特定的目标来过滤@ReferencedProjects?

关于如何处理这种情况的任何其他想法?

【问题讨论】:

    标签: msbuild


    【解决方案1】:

    你不能做你所要求的。但是你也许可以通过批处理来实现它。

    <Project xmlns=''>
        <ItemGroup>
            <ReferencedProjects Include="webcontrols.csproj">
                <Type>Web</Type>
            </ReferencedProjects>
            <ReferencedProjects Include="utils.csproj">
                <Type>NonWeb</Type>
            </ReferencedProjects>
        </ItemGroup>
    
       <Target Name="BuildWebProjects">
            <MSBuild Projects="@(ReferencedProjects)" Condition=" '%(ReferencedProjects.Type)' == 'Web' " />
       </Target>
    
    </Project>
    

    搜索 MSBuild Batching 并在 sedodream.com 上找到一些结果以获取更多信息 信息。

    我应该对此进行扩展吗?

    【讨论】:

    • 这可能是 MSBuild 的最佳选择,但它创建的大量手动工作使我无法使用它。
    • 还有一件事,它是“ProjectReference”,而不是“ReferencedProjects”
    • 好的,我只是在使用您在示例中创建的名称。
    猜你喜欢
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    相关资源
    最近更新 更多