MSBuild Targets - How to detect changes to .csproj content files

那年仲夏 提交于 2019-12-25 08:32:47

问题


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.


回答1:


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)')"/>        



来源:https://stackoverflow.com/questions/40552309/msbuild-targets-how-to-detect-changes-to-csproj-content-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!