pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

MSBuild 復制動態生成的文件作為項目依賴項的一部

MSBuild to copy dynamically generated files as part of project dependency(MSBuild 復制動態生成的文件作為項目依賴項的一部分)
本文介紹了MSBuild 復制動態生成的文件作為項目依賴項的一部分的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個自定義 msbuild 任務,它正在生成一些輸出文件到 ProjectA 的輸出目錄 ($(TargetDir)).當前代碼是這樣的:

I have a custom msbuild task that is generating some output files to the output directory ($(TargetDir)) of a ProjectA. Current code is something like this:

<MyCustomTask ...>
   <Output TaskParameter="OutputFiles" ItemName="FileWrites"/>
</MyCustomTask>

A ProjectB 正在引用 ProjectA 但問題是在構建 ProjectB 時,MyCustomTask 生成的文件不會復制到 ProjectB 的輸出目錄.

A ProjectB is referencing ProjectA but the problem is that when building ProjectB, generated files by MyCustomTask are not copied to the output directory of the ProjectB.

我們如何獲取動態生成的附加文件以作為 MSBuild 項目依賴項的一部分進行復制?

How can we get dynamically generated additional files to be copied as part of project dependency with MSBuild?

推薦答案

我終于設法從 Project B 自動執行復制,而無需修改它.IIya 離解決方案不遠,但事實是我無法靜態生成,因為使用 MyCustomTask 從 Project A 生成的文件列表是動態的.在深入了解 Microsoft.Common.targets 之后,我發現 ProjectB 將通過調用目標 GetCopyToOutputDirectoryItems 來獲取 Project A 的輸出列表.該目標依賴于 AssignTargetPaths,而 AssignTargetPaths 本身又依賴于目標列表屬性 AssignTargetPathsDependsOn.

I have finally managed to perform automatically the copy from Project B without having to modify it. IIya was not so far from the solution, but the fact is that I cannot generate statically as the list of files to generate from Project A with MyCustomTask is dynamic. After digging more into Microsoft.Common.targets, I have found that ProjectB will get the list of output from Project A by calling the target GetCopyToOutputDirectoryItems. This target is dependent from AssignTargetPaths which itself is dependent on the target list property AssignTargetPathsDependsOn.

因此,為了動態生成內容并通過標準項目依賴項自動復制此內容,我們需要在兩個不同的地方掛鉤 Project A:

So in order to generate dynamically content and to get this content being copied automatically through standard project dependency, we need to hook Project A at two different places:

  • AssignTargetPathsDependsOn 中,因為它由 Project BProject A 上通過 GetCopyToOutputDirectoryItems 間接調用.當 PrepareResource 被調用時,它也被 Project A 間接調用.在這里,我們只是輸出將生成(由Project A)或由Project B 使用的文件列表.AssignTargetPathsDependsOn 將調用一個自定義任務 MyCustomTaskList,它只負責輸出文件列表(但不生成它們),這個文件列表將使用 CopyOutputDirectory.
  • BuildDependsOn 中以實際生成 Project A 中的內容.這將調用生成內容的 MyCustomTask.
  • In AssignTargetPathsDependsOn as it is called indirectly by Project B on Project A through GetCopyToOutputDirectoryItems. And also it is indirectly called by Project A when PrepareResource is called. Here, we are just outputing the list of files that will be generated (by Project A) or consumed by Project B. AssignTargetPathsDependsOn will call a custom task MyCustomTaskList which is only responsible to output the list of files (but not to generate them), this list of files will create dynamic "Content" with CopyOutputDirectory.
  • In BuildDependsOn in order to actually generate the content in Project A. This will call MyCustomTask that will generate the content.

所有這些都是在 ProjectA 中這樣設置的:

All of this was setup like this in ProjectA:

<!-- In Project A -->

<!-- Task to generate the files -->
<UsingTask TaskName="MyCustomTask" AssemblyFile="$(PathToMyCustomTaskAssembly)"/>

<!-- Task to output the list of generated of files - It doesn't generate the file -->
<UsingTask TaskName="MyCustomTaskList" AssemblyFile="$(PathToMyCustomTaskAssembly)"/>

<!-- 1st PART : When Project A is built, It will generate effectively the files -->
<PropertyGroup>
  <BuildDependsOn>
    MyCustomTaskTarget;
    $(BuildDependsOn);
  </BuildDependsOn>
</PropertyGroup>

<Target Name="MyCustomTaskTarget">
  <!-- Call MyCustomTask generate the files files that will be generated by MyCustomTask -->
  <MyCustomTask
      ProjectDirectory="$(ProjectDir)"
      IntermediateDirectory="$(IntermediateOutputPath)"
      Files="@(MyCustomFiles)"
      RootNamespace="$(RootNamespace)"
      >
  </MyCustomTask>
</Target>

<!-- 2nd PART : When Project B is built, It will call GetCopyToOutputDirectoryItems on ProjectA so we need to generate this list when it is called  -->
<!-- For this we need to override AssignTargetPathsDependsOn in order to generate the list of files -->
<!-- as GetCopyToOutputDirectoryItems  ultimately depends on AssignTargetPathsDependsOn -->
<!-- Content need to be generated before AssignTargets, because AssignTargets will prepare all files to be copied later by GetCopyToOutputDirectoryItems -->
<!-- This part is also called from ProjectA when target 'PrepareResources' is called -->
<PropertyGroup>
  <AssignTargetPathsDependsOn>
    $(AssignTargetPathsDependsOn);
    MyCustomTaskListTarget;
  </AssignTargetPathsDependsOn>
</PropertyGroup>

<Target Name="MyCustomTaskListTarget">

  <!-- Call MyCustomTaskList generating the list of files that will be generated by MyCustomTask -->
  <MyCustomTaskList
      ProjectDirectory="$(ProjectDir)"
      IntermediateDirectory="$(IntermediateOutputPath)"
      Files="@(MyCustomFiles)"
      RootNamespace="$(RootNamespace)"
      >
      <Output TaskParameter="ContentFiles" ItemName="MyCustomContent"/>
  </MyCustomTaskList>

  <ItemGroup>
    <!--Generate the lsit of content generated by MyCustomTask -->
    <Content Include="@(MyCustomContent)" KeepMetadata="Link;CopyToOutputDirectory"/>
  </ItemGroup>
</Target>

此方法適用于任何使用 Common.Targets 的 C# 項目(因此它適用于純桌面、WinRT XAML 應用程序或 Windows Phone 8 項目).

This method is working with anykind of C# projects that is using Common.Targets (so It is working with pure Desktop, WinRT XAML App or Windows Phone 8 projects).

這篇關于MSBuild 復制動態生成的文件作為項目依賴項的一部分的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數)
Standard deviation of generic list?(通用列表的標準偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創建一個 IAwaitable 的類)
主站蜘蛛池模板: 钢化玻璃膜|手机钢化膜|钢化膜厂家|手机保护膜-【东莞市大象电子科技有限公司】 | 外贸资讯网 - 洞悉全球贸易,把握市场先机 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 涿州网站建设_网站设计_网站制作_做网站_固安良言多米网络公司 | 电子天平-华志电子天平厂家 | 高压包-点火器-高压发生器-点火变压器-江苏天网 | 数控车床-立式加工中心-多功能机床-小型车床-山东临沂金星机床有限公司 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 科研ELISA试剂盒,酶联免疫检测试剂盒,昆虫_植物ELISA酶免试剂盒-上海仁捷生物科技有限公司 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 深圳侦探联系方式_深圳小三调查取证公司_深圳小三分离机构 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 无负压供水设备,消防稳压供水设备-淄博创辉供水设备有限公司 | 智慧养老_居家养老_社区养老_杰佳通 | 选矿设备,选矿生产线,选矿工艺,选矿技术-昆明昆重矿山机械 | 东风体检车厂家_公共卫生体检车_医院体检车_移动体检车-锦沅科贸 | 对辊式破碎机-对辊制砂机-双辊-双齿辊破碎机-巩义市裕顺机械制造有限公司 | 亮化工程,亮化设计,城市亮化工程,亮化资质合作,长沙亮化照明,杰奥思【官网】 | 微动开关厂家-东莞市德沃电子科技有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 | 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 阁楼货架_阁楼平台_仓库仓储设备_重型货架_广州金铁牛货架厂 | 紫外可见光分光度计-紫外分光度计-分光光度仪-屹谱仪器制造(上海)有限公司 | 紫外可见光分光度计-紫外分光度计-分光光度仪-屹谱仪器制造(上海)有限公司 | 上海防爆真空干燥箱-上海防爆冷库-上海防爆冷柜?-上海浦下防爆设备厂家? | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 气力输送设备_料封泵_仓泵_散装机_气化板_压力释放阀-河南锐驰机械设备有限公司 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 申江储气罐厂家,储气罐批发价格,储气罐规格-上海申江压力容器有限公司(厂) | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 丙烷/液氧/液氮气化器,丙烷/液氧/液氮汽化器-无锡舍勒能源科技有限公司 | 冷藏车-东风吸污车-纯电动环卫车-污水净化车-应急特勤保障车-程力专汽厂家-程力专用汽车股份有限公司销售二十一分公司 | 泥沙分离_泥沙分离设备_泥砂分离机_洛阳隆中重工机械有限公司 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 精密模具制造,注塑加工,吹塑和吹瓶加工,EPS泡沫包装生产 - 济南兴田塑胶有限公司 | 北京开源多邦科技发展有限公司官网| 济南冷库安装-山东冷库设计|建造|冷库维修-山东齐雪制冷设备有限公司 |