How to add a file to "clean solution" files

B

Bob Altman

Hi,

My VB project (VS 2005) has a post-build event that runs a program that
creates an executable file in the target directory (that is, the same folder
that contains the normal build results). However, since VS (or, more
specifically, MSBuild) doesn't know about this new executable, it isn't
deleted when I select Build->Clean Solution. How do I tell my VB project
about this file so that it gets deleted when I "clean" the build results?

TIA - Bob
 
W

WenYuan Wang [MSFT]

Hello Bob,

According to your description, you need delete a special file when VS
cleans solution.
If this is the case, following code should be helpful. Please append it
into .vbproj file.

Delete the file before VS.
<Project>
..
<Target Name="BeforeClean">
<Delete Files="$(MSBuildProjectDirectory)\bin\Debug\test.txt" />
</Target>
..
</Project>

Or delete the file after VS.
<Project>
..
<Target Name="AfterClean">
<Delete Files="$(MSBuildProjectDirectory)\bin\Debug\test.txt" />
</Target>
</Project>

Hope this helps. Please try this method and let me know whether this is
what you need. I'm glad to assist you.
Have a great day.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Bob Altman

Hi Wen Yuan

Is it a good idea to edit the vbproj file? How does the IDE sort out its
content from my content?

- Bob
 
W

WenYuan Wang [MSFT]

Hello Bob,
Thanks for your reply.

In order to modify the build process, it is necessary and safe to add task
in .vbproj file.

If you add the task in "BeforeClean" Target, VS 2005 IDE will execute the
custom Tasks before the core clean functionality is invoked.
On the other side, adding the task in "AfterClean" Target means VS 2005 IDE
executes the custom Tasks before the core clean functionality is invoked.

Hope this helps. Let me know if you still have anything unclear. I'm glad
to work with you.
Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Bob Altman

Thanks Wen Yuan!

Here's a little more info for those who may come along looking for help with
this topic:

The MSDN Help topic "How to: Extend the Visual Studio Build Process" is a
good starting point for learning how to do this.

Also, a minor to tweak to Wen Yuan's suggested code: In order to locate the
folder that contains the files built by VS in the currently selected target
(debug, release, etc.), you can use $(OutputPath), like this:

</Project>
... VS content ...
<Target Name="AfterClean">
<Delete Files="$(OutputPath)my_file.exe" />
<Delete Files="$(OutputPath)my_file.pdb" />
</Target>
</Project>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top