MSBuild目标-如何检测对.csproj内容文件的更改 [英] MSBuild Targets - How to detect changes to .csproj content files

查看:136
本文介绍了MSBuild目标-如何检测对.csproj内容文件的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要完成的工作是在构建过程中检测项目的更改,因此我可以设置一个标志来指示项目已更改.我已经弄清楚了如何利用增量构建和CoreCompileDependsOn来检测C#组件何时发生了更改.但是,当项目的内容文件发生更改时,这似乎不会触发.据我了解,根据项目中内容文件的设置,将在某处指定一个SkipUnchangedFiles ="true"的复制任务,复制到输出目录(不复制,始终复制,如果更新则复制).我不完全确定此过程在哪里发生,可能是Microsoft.CSharp.targets文件?有人可以建议我如何添加一个仅在将更新文件复制到bin输出后才执行的依赖任务吗?一个非常简单的示例就足够了.

What I'm trying to accomplish is detecting changes to projects during build so I can set a flag indicating that the project was changed. I've already figured out how to detect when a C# component has changed by utilizing incremental builds and CoreCompileDependsOn. But this doesn't seem to trigger when a content file of a project has changed. From what I understand, there would be a Copy task somewhere specifying SkipUnchangedFiles="true" depending on the setting of the content file within the project, Copy to Output Directory (Do not copy, Copy Always, Copy if Newer). I'm not entirely sure where this process happens, possibly the Microsoft.CSharp.targets file? Could someone please advise as to how I would add a dependent task that executes only if an updated file was copied to the bin output? A very simple example would suffice.

推荐答案

我知道了.仅当在构建过程中更改了设置为如果更新时复制"的任何内容文件时,才会写入一个以项目名称命名的文本文件.

I figured it out. This will write a text file with the name of the project ONLY if any content files that have 'Copy If Newer' set have been changed during a build:

      <Target Name="ContentFilesUpdated" AfterTargets="_CopyOutOfDateSourceItemsToOutputDirectory" Condition="'$(IsDesktopBuild)' == 'False'">
    <WriteLinesToFile  
        File="@(ProductChangeFile)"  
        Lines="$(ProjectName)"  
        Overwrite="false"
        Encoding="Unicode" Condition="!Exists('@(ProductChangeFile)')"/>        

这篇关于MSBuild目标-如何检测对.csproj内容文件的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆