MSBuild: adding / copying empty folders using the Zip / Copy task

I am trying to create a copy / zip precompiled site that contains empty folders (after preliminary compilation). It seems that empty folders are not included in the list of items after the CreateItem task. How can I take care of empty folders?

thanks

+6
build-automation msbuild zip msbuildcommunitytasks
source share
4 answers

I don’t feel that this is the most elegant solution, but what we did before is creating a folder in the solution and a text file named placeholder.txt or something similar, as well as setting properties for the text file that will be included in the assembly. The result is a folder in which you want to contain it a file that you do not need. Then we delete the placeholder.txt file before we zip it, everything inside the script assembly.

Not elegant, but he does the job in our scenario.

+4
source share

MSBuild will not create empty folders when creating items. You will need to use a task (for example, the FindUnder task from the MSBuild Extension Pack ) if you want you to be able to place empty folders in an item.

Said Ibrahim Hashimi

My book: Inside Microsoft Build Engine: Using MSBuild and Team Foundation Build

+4
source share

To easily copy empty folders, you can use the exec task to invoke RoboCopy. You can specify the / MIR argument, which will reflect the entire tree that you are trying to copy, including empty folders.

Example:

<Exec Command="robocopy &quot;$(SourceLocation)\&quot; &quot;$(TargetLocation)\&quot; /MIR" IgnoreExitCode="true" /> 

Similarly, you can use the exec task to invoke a compression utility that has a command line interface to get zip with empty folders.

+1
source share

It may be a little complicated, but I think it works if all your files and folders are in the same root and you zip this root folder without using wildcards (just using "."):

 <PropertyGroup> <SourcePath>.\path\to\rootFolder</SourcePath> <FinalZipFileName>.\path\to\destination\myzip.zip</FinalZipFileName> </PropertyGroup> <Target Name="MyApplicationZip" > <Zip ZipFileName="$(FinalZipFileName)" WorkingDirectory="$(SourcePath)" Files="$(SourcePath)\." ZipLevel="9" /> </Target> 
0
source share

All Articles