AfterClean Target Doesn't Get Invoked When I Clean The Project

南笙酒味 提交于 2019-12-13 05:15:32

问题


I've added a 'BeforeClean' and an 'AfterClean' target to my .csproj file, originally designed to delete some build artifacts in locations outside the normal build path.

When I did a "clean" on the project, I could tell that the files weren't getting deleted; so I dumbed down the action to just spit a message out. Like the delete command, the message command isn't getting invoked (I'm expecting to see the message in the 'Output' window).

The only relevant advice I could find on the web was to make sure that you do your target definitions after you import the Microsoft.CSharp.targets file. I'm including the clip of my .csproj file with enough detail to show where my target defs are vis-a-vis the import.

As far as I can tell, I'm doing everything right; why would my targets not get invoked?

Thanks in advance.

[Update and FYI: I was able to get the Target to fire when changing Importance from 'normal' to 'high.']

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
        <PropertyGroup>
            <PreBuildEvent>
            </PreBuildEvent>
        </PropertyGroup>
    <Target Name="BeforeClean">
        <Message Text="Hello Clean World!" Importance="normal" ContinueOnError="true"/>
    </Target>
    <Target Name="AfterClean">
        <Message Text="Goodbye Clean World!" Importance="normal" ContinueOnError="true"/>
    </Target>
</Project>

回答1:


It actually is getting invoked, you just can't see it. Run msbuild.exe with /verbosity:normal. Or change the IDE setting: Tools + Options, Projects and Solutions, Build and Run. Or change the Importance attribute to high.



来源:https://stackoverflow.com/questions/18723803/afterclean-target-doesnt-get-invoked-when-i-clean-the-project

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