How to delete files in Visual Studio Pre-build event command line

Viewed 67640

I am trying to delete files in my $(TargetDir) within visual studio before building a project.

How do you have to format command line to get around this problem I am getting below? alt text

7 Answers

Try

cd $(TargetDir)
del *.tif

As jvenema pointed out, your $(TargetDir) is expanding into a path containing spaces in the folder names which is breaking the delete command.

Try adding quotes around the directory.

For DOTNET Core, your quotes need to be escaped, like this:

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
  <Exec Command="del &quot;$(ProjectDir)wwwroot\_framework\*.*&quot; /q" />
</Target>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="copy &quot;$(ProjectDir)..\Client\bin\Debug\net5.0\wwwroot\_framework\*.*&quot; &quot;$(ProjectDir)wwwroot\_framework\&quot;" />
</Target>
Related