Search code examples
asp.netvisual-studio-2008msbuildweb-deployment-project

Is there a way to stop VS2008 Web Deployment Project from creating Source folder when using ExcludeFromBuild?


When excluding files in Web Deployment Project using ExcludeFromBuild e.g.

  <ItemGroup>
      <ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.csproj*"/>
  </ItemGroup>

I end up with a Source folder containing all next to the Release and Debug folders. This folder does not show up if I don't use any ExcludeFromBuild option.

Is there a way to stop this folder from being created? Why is it created in the first place?


Solution

  • In Misrosoft.WebDeployments.targets file (which web deployment project file imports) there's a _CopyBeforeBuild target which copies all the source files when ExcludeFromBuild property isn't empty or EnableCopyBeforeBuild is specified:

    ...
    
    <CopyBeforeBuildTargetPath>$(MSBuildProjectDirectory)\Source</CopyBeforeBuildTargetPath>
    
    ...
    
    <Target Name="_CopyBeforeBuild" Condition=" '$(EnableCopyBeforeBuild)' == 'true' or '@(ExcludeFromBuild)' != ''  ">
        ...
        <RemoveDir Directories="$(CopyBeforeBuildTargetPath)"/>
        <MakeDir Directories="$(CopyBeforeBuildTargetPath)"/>
        <Copy SourceFiles="@(_WebFiles)" DestinationFolder="$(CopyBeforeBuildTargetPath)\%(_WebFiles.SubFolder)%(_WebFiles.RecursiveDir)" />
        ...
    </Target>
    

    So the script creates the source directory and doesn't remove it. That directory annoys me too so I add next lines to web deployment project file:

    <Target Name="AfterBuild">
        <RemoveDir Directories="$(CopyBeforeBuildTargetPath)" />
    </Target>