VS2008 custom clean for C++

Bruce Mahfood 6 Reputation points
2021-02-09T14:19:15.797+00:00

Not sure if this is the correct place to ask this, but here goes:

I am currently on a project which was created using VS2008 and is at the moment unable to be moved to a newer version of VS because of dependencies. I have added a build event that creates new files in the solution folder, and those new files are currently not deleted unless associated cpp/h files are updated to a timestamp later than one of the new files. This means that when a clean is done on the solution, the new files remain uncleaned. We want to change it so that when we run clean, these files are deleted (by a command line that specifies them by wildcarded name format).

I have looked for some time now and have come up only with a suggestion to add the following to my vcproj file:

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

but from the context of the posts that talk about this, and of the referenced documentation page, and the fact that the poster actually says to add this to the csproj file, it seems this is associated with C#, and it looks like it may also be associated with later versions of VS. I have tried adding this block to my vcproj file, but I get an error reloading the project. The error says that "Target" is not recognized.

My question is whether this is actually something that I could use in VS2008 for adding a custom step to cleaning a C++ project. If it is correct, then where do I place this in the vcproj file such that reloading the project will not give an error. And if it is not correct, is there a syntax that would be able to be used for VS2008 in a C++ project to do such a custom clean step.

If I cannot find such a syntax, the obvious next step is to run a bat file by hand whenever we want to clean these files. If I can avoid that, that would be great. So any help would be appreciated.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,001 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,271 Reputation points Microsoft Vendor
    2021-02-11T08:19:54.513+00:00

    Hi @Bruce Mahfood ,

    You can try to put the “Target” element inside of <VisualStudioProject> </VisualStudioProject>tag and outside of the <Globals></Globals> tag, for example:

    66778-deletefile.png

    Note that it is not available to use wildcards in the Delete task, if you want to delete multiple files, you can refer to this document: Delete Task and this document: ItemGroup Element and try to use ItemGroup element.(The first document also mentioned this)

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.