我正在使用Visual Studio 2010。我已将项目输出指向一个特定的文件夹,该文件夹在构建时将包含所有的DLL和EXE文件。但是当我清理解决方案时,该文件夹并没有被清理,DLL仍然存在其中。
有人能告诉我如何处理清理解决方案命令以清除我想要清理的文件夹吗?我尝试使用MSBuild,并处理BeforeClean和AfterClean目标,但没有提供所需的结果。
我正在使用Visual Studio 2010。我已将项目输出指向一个特定的文件夹,该文件夹在构建时将包含所有的DLL和EXE文件。但是当我清理解决方案时,该文件夹并没有被清理,DLL仍然存在其中。
有人能告诉我如何处理清理解决方案命令以清除我想要清理的文件夹吗?我尝试使用MSBuild,并处理BeforeClean和AfterClean目标,但没有提供所需的结果。
Sergio提供的答案应该是有效的,但我认为更好的方法是覆盖BeforeClean/AfterClean目标。这些是由Microsoft提供的构建/清理过程的钩子。当您清理时,VS会调用目标:BeforeClean; Clean; AfterClean,默认情况下第一个和最后一个都不做任何事情。
在您现有的.csproj文件中,您可以添加以下内容:
<Target Name="BeforeClean">
<!-- DO YOUR STUFF HERE -->
</Target>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
<ItemGroup>
<CleanOutCatalogFiles Include="..\..\bin\$(Configuration)\**\*.dll">
<Visible>false</Visible>
</CleanOutCatalogFiles>
<CleanOutCatalogFiles Include="..\..\bin\$(Configuration)\**\*.exe">
<Visible>false</Visible>
</CleanOutCatalogFiles>
</ItemGroup>
<Target Name="Build">
</Target>
<Target Name="Rebuild"
DependsOnTargets="Clean;Build">
</Target>
<Target Name="Clean"
Condition="'@(CleanOutCatalogFiles)'!=''">
<Message Text="Cleaning Output Dlls and EXEs" Importance="high" />
<Delete Files="@(CleanOutCatalogFiles)" />
</Target>
</Project>
<Target Name="BeforeClean"> <RemoveDir Directories="$(MSBuildProjectDirectory)\mydir" /> </Target>
- Jeroen