Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 996
Shaz Avatar asked Jan 06 '11 19:01

Shaz


People also ask

How do I exclude files from a folder?

Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection. Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select from files, folders, file types, or process.

How do I ignore a folder in Visual Studio?

You can use Visual Studio to exclude a file from a solution by context-clicking the file in Solution Explorer and selecting Exclude from Project in the context menu.

How do I get excluded files in Visual Studio?

We can right click on the file, choose properties, go to General and click on Excluded From Build, then choose Yes or No to exclude or re-include.

How do I exclude a project in Visual Studio?

On the menu bar, choose Build > Configuration Manager. In the Project contexts table, locate the project you want to exclude from the build. In the Build column for the project, clear the check box. Choose the Close button, and then rebuild the solution.


1 Answers

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)

like image 140
Roman Starkov Avatar answered Sep 27 '22 17:09

Roman Starkov