forked from moozzyk/MSBuild-Tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.tasks
More file actions
66 lines (63 loc) · 2.56 KB
/
common.tasks
File metadata and controls
66 lines (63 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="Zip" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<InputFileNames ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<OutputFileName ParameterType="System.String" Required="true" />
<OverwriteExistingFile ParameterType="System.Boolean" Required="false" />
</ParameterGroup>
<Task>
<Reference Include="System.IO.Compression" />
<Using Namespace="System.IO.Compression" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var fileMode = OverwriteExistingFile ? FileMode.Create : FileMode.CreateNew;
using (var archive = new ZipArchive(new FileStream(OutputFileName, fileMode), ZipArchiveMode.Create))
{
foreach (var inputFileName in InputFileNames.Select(f => f.ItemSpec))
{
var archiveEntry = archive.CreateEntry(Path.GetFileName(inputFileName));
using (var fs = new FileStream(inputFileName, FileMode.Open))
{
using (var zipStream = archiveEntry.Open())
{
fs.CopyTo(zipStream);
}
}
}
}
]]>
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="ZipDir" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<InputBaseDirectory ParameterType="System.String" Required="true" />
<OutputFileName ParameterType="System.String" Required="true" />
<OverwriteExistingFile ParameterType="System.Boolean" Required="false" />
<IncludeBaseDirectory ParameterType="System.Boolean" Required="false" />
</ParameterGroup>
<Task>
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Using Namespace="System.IO.Compression" />
<Code Type="Fragment" Language="cs">
<![CDATA[
if (File.Exists(OutputFileName))
{
if (!OverwriteExistingFile)
{
return false;
}
File.Delete(OutputFileName);
}
ZipFile.CreateFromDirectory
(
InputBaseDirectory, OutputFileName,
CompressionLevel.Optimal, IncludeBaseDirectory
);
]]>
</Code>
</Task>
</UsingTask>
</Project>