Evan Park
Evan Park

Reputation: 538

MSBuild ZipDirectory Output Different when Building Solution and Building Individual Project

I'm having an issue with MSBuild ZipDirectory command, where the zipped output file differs between when built by individual project and when built for entire solution.

For example, The expected zip file looks like below:

A.txt

B.txt

C.txt

The zipped file looks as expected when built as individual project.

However, When solution is build as a whole, The zipped file looks like below, missing some files:

A.txt

B.txt

What is causing such issue??

Upvotes: 1

Views: 1442

Answers (1)

Mr Qian
Mr Qian

Reputation: 23715

MSBuild ZipDirectory Output Different when Building Solution and Building Individual Project

I wonder if you use ZipDirectory task to compress some certain files in your project. I have tested the command in different projects in the same solution and did not face the same issue as you said. So please check this:

1) If you just compress some content files in the project, try to create a new folder in Solution Explorer called resource and then put any files you want to compress into this. And remember to set this target executes after build process.

<Target Name="ZipOutputPath" AfterTargets="Build">
    <ZipDirectory
        SourceDirectory="$(MSBuildProjectDirectory)\resource"
        DestinationFile="$(MSBuildProjectDirectory)\output.zip" />
  </Target>

2) If you want to compress the files of the output folder, please make sure that you have set Copy to Output Directory of the specific files to Copy if newer.

Note :please check if there are some extra targets which will delete some files like C.txt or there is some extra condidtions to limit this.

Build Solution means that it can build all the projects at the same time so I wonder if some extra projects have some configuration which will cause this behavior in the first project.

3) Besides, you can also try zip task to realize this:

<Target Name="zipfiles" AfterTargets = "Build">
 <ItemGroup>
    <ZipFiles Include="xxxxx\A.txt" />
    <ZipFiles Include="xxxxx\B.txt" />
    <ZipFiles Include="xxxxx\C.txt" />
  </ItemGroup>
  <Zip OutputFilename="$(OutputPath)Project.zip" Files="@(ZipFiles)" />
 </Target>

In addition, if all of these did not help, there might be a situation where you might have a problem with your VS environment. Due to it, you can follow these steps:

A) close VS instance, delete .vs hidden folder under the solution path,bin and obj folder. Then restart your solution and then build again to see whether the issue persists.

B) use devenv /safemode to start VS and then test whether the issue is caused by third party extensions, packages.

C) do a repair in VS Installer.

If I misunderstand your issue, please share more detailed info and feel free to let us know.

Upvotes: 3

Related Questions