How to exclude specific folders when copying using MSBUILD

It sounds like it should be pretty simple, but I am having problems with excluding folders when using the MSBUILD copy task. That'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)"/>

The element group section has an ExcludeFromBuild element, which lists the types of files that I want to exclude. In addition, I want to exclude the "obj" and "Web References" folders.

How can i do this? Please let me know if more information is needed. Thank.

Shahzad

+3
source share
1 answer

To do this, you need to create a new ItemGroup. I added AppFolderWithExclusionsbelow:

<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 contain typos)

+4
source

Source: https://habr.com/ru/post/1783931/


All Articles