Shaz
Shaz

Reputation: 2704

How to exclude certain folders while copying using MSBUILD

Seems like it should be fairly simple but I'm having trouble excluding folders when using the MSBUILD copy task. Here's what I'm doing:

   <ItemGroup>
        <Compile Include="$(_SolutionPath)$(_SolutionName)" />
        <ProjectFiles Include="..\$(_WebDirectory)\*.csproj" Exclude="*.master.csproj"/>
        <ExcludeFromBuild Include="..\$(_WebDirectory)\**\*.cs; ..\$(_WebDirectory)\**\*.sln; ..\$(_WebDirectory)\**\*.csproj; ..\$(_WebDirectory)\Web References; ..\$(_WebDirectory)\obj;"/>
        <AppFolder Include="..\$(_WebDirectory)\**\*.*" Exclude="$(ExcludeFromBuild)"/>
    </ItemGroup>

<Copy SourceFiles="@(AppFolder)" DestinationFiles="c:\test\%(RecursiveDir)%(FileName)%(Extension)"/>

In the item group section I have an ExcludeFromBuild item which lists out the file types i want to exclude. On top of that I want to exclude the "obj" and "Web References" folder.

How can I accomplish this? Please let me know if more information is needed. Thank you.

shahzad

Upvotes: 5

Views: 9939

Answers (1)

Roman Starkov
Roman Starkov

Reputation: 61512

You need to create a new ItemGroup for that. I've added AppFolderWithExclusions below:

<ItemGroup>
     <Compile Include="$(_SolutionPath)$(_SolutionName)" />
     <ProjectFiles Include="..\$(_WebDirectory)\*.csproj" Exclude="*.master.csproj"/>
     <ExcludeFromBuild Include="..\$(_WebDirectory)\**\*.cs; ..\$(_WebDirectory)\**\*.sln; ..\$(_WebDirectory)\**\*.csproj; ..\$(_WebDirectory)\Web References; ..\$(_WebDirectory)\obj;"/>
     <AppFolder Include="..\$(_WebDirectory)\**\*.*" Exclude="$(ExcludeFromBuild)"/>

     <AppFolderWithExclusions Include="@(AppFolder)" Exclude="obj\**\*.*;Web References\**\*.*" />
 </ItemGroup>

(untested; may include syntax typos)

Upvotes: 7

Related Questions