Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Remove dependency on MSBuild.Community.Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
terrajobst committed Apr 14, 2013
1 parent c40b53f commit a95249f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Build/Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

<UsingTask AssemblyFile="$(CustomTasksDir)XsdDocumentation.Build.dll"
TaskName="XsdDocumentation.Build.GetFileVersionInfo" />
<UsingTask AssemblyFile="$(LibDir)MSBuildCommunityTasks\MSBuild.Community.Tasks.dll"
TaskName="MSBuild.Community.Tasks.Zip" />
<UsingTask AssemblyFile="$(CustomTasksDir)XsdDocumentation.Build.dll"
TaskName="XsdDocumentation.Build.Zip" />

<!-- Build -->

Expand Down Expand Up @@ -213,7 +213,7 @@

<!-- Generate Release -->

<Target Name="GenerateRelease">
<Target Name="GenerateRelease" DependsOnTargets="CompileBuildTasks">
<ItemGroup>
<GeneratedBuildServerFiles Include="$(GeneratedBinaries)\**\*.*" />
<GeneratedSourceCodeFiles Include="$(GeneratedSourceCode)\**\*.*" />
Expand Down
Binary file not shown.
8 changes: 7 additions & 1 deletion Source/XsdDocumentation.Build/XsdDocumentation.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XsdDocumentation.Build</RootNamespace>
<AssemblyName>XsdDocumentation.Build</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,6 +33,7 @@
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugSymbols>true</DebugSymbols>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Code Analysis|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -42,19 +44,23 @@
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="GetFileVersion.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Zip.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
62 changes: 62 additions & 0 deletions Source/XsdDocumentation.Build/Zip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace XsdDocumentation.Build
{
public sealed class Zip : Task
{
public ITaskItem WorkingDirectory { get; set; }

[Required]
public ITaskItem ZipFileName { get; set; }

[Required]
public ITaskItem[] Files { get; set; }

public override bool Execute()
{
try
{
var workingDirectory = WorkingDirectory.ItemSpec;
var zipFileName = ZipFileName.ItemSpec;
var fileNames = Files.Select(f => f.ItemSpec);
CreateZipArchive(workingDirectory, zipFileName, fileNames);

}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
}

return !Log.HasLoggedErrors;
}

private static void CreateZipArchive(string workingDirectory, string zipFileName, IEnumerable<string> fileNames)
{
using (var fileStream = File.Create(zipFileName))
using (var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create))
{
foreach (var fileName in fileNames)
{
var relativePath = GetRelativePath(fileName, workingDirectory);
zipArchive.CreateEntryFromFile(fileName, relativePath, CompressionLevel.Optimal);
}
}
}

private static string GetRelativePath(string fileName, string workingDirectory)
{
if (!fileName.StartsWith(workingDirectory, StringComparison.OrdinalIgnoreCase))
return Path.GetFileName(fileName);

var backslashCompensation = workingDirectory.EndsWith("\\") ? 1 : 0;
return fileName.Substring(workingDirectory.Length + backslashCompensation);
}
}
}

0 comments on commit a95249f

Please sign in to comment.