如何在 Visual Studio 2008 中创建自定义清理(清理后)事件?

在我们的构建过程中,对于每个项目,我们使用构建后事件将我们的可执行文件复制到单独的部署目录中.这很有效,但问题是我们在执行清理解决方案/清理项目后遇到了陈旧文件的问题.我想设置一个清理"事件来删除复制的文件,而 Visual Studio 2008 似乎没有在项目属性页面中提供选项.

In our build process, for each project we use Post Build events to copy our executable files into a separate deployment directory. That works just peachy, but the problem is that we run into problems with stale files after performing a Clean Solution/Clean Project. I'd like to set up a "Clean" event that deletes the copied file and Visual Studio 2008 does not seem to provide an option in the project properties page.

它有:

Build Events:
   Pre-Build Event
   Pre-Link Event
   Post-Build Event
Custom Build Step
   General

我想找到的是在清理项目时执行任意命令行的某种方法.

What I'd like to find is some way to execute an arbitrary command line when the project is cleaned.

推荐答案

您可以在 csproj 文件中使用 MSBuild 目标语法.例如

You can use the MSBuild target syntax in your csproj file. e.g

  <Target Name="AfterClean">
    <Delete Files="$(OutDir)$(TargetName).exe" ContinueOnError="true" />
  </Target>

MSBuild 团队博客中描述了一种直接在 Visual Studio IDE 中编辑 .csproj 文件的巧妙方法,但这是我的第一篇文章,因此我只能包含一个超链接.(简而言之:卸载项目,然后右键单击它以查看条目编辑 [项目].csproj"……您的 csproj 将作为一个 xml 文件出现在 IDE 中,其中包含有关元素和属性的智能感知.太棒了!)

There is a neat way to edit your .csproj file directly in the Visual Studio IDE described in the MSBuild team blog, but this is my first post so I can only include one hyperlink. (briefly: Unload the project, then right-click on it to see the entry "Edit [project].csproj" ... your csproj will come up in the IDE as an xml file with intellisense on elements and attributes. Wonderful!)

自定义目标的完整列表是 此处.

A full list of custom Targets is here.

相关文章