Skip to content

Commit

Permalink
Update to use 7zip to create Kudu.zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaomin Wu committed May 18, 2016
1 parent 09c4a18 commit da3e64c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ nuget.exe
Kudu.Services.Web/commit.txt
Setup/WebPiCmdSetup.log
Kudu.Services.Web/node_modules/
.vs/
.vs/
Build/7zip/
64 changes: 64 additions & 0 deletions Build/7zip.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Download 7zip if it does not already exist -->
<Download7Zip Condition=" '$(Download7Zip)' == '' ">true</Download7Zip>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<File7ZipPath>$(MsBuildThisFileDirectory)\7zip.zip</File7ZipPath>
<Exe7ZipPath>$(MsBuildThisFileDirectory)\7zip\7za.exe</Exe7ZipPath>
</PropertyGroup>

<Target Name="Ensure7Zip">
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download 7zip once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_Download7Zip" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;Platform=AnyCPU" />
</Target>

<Target Name="_Download7Zip">
<Download7Zip OutputFileName="$(File7ZipPath)" Condition=" '$(Download7Zip)' == 'true' AND !Exists('$(Exe7ZipPath)')" />
</Target>

<UsingTask TaskName="Download7Zip" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFileName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression"/>
<Reference Include="System.IO.Compression.FileSystem"/>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.IO.Compression" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFileName = Path.GetFullPath(OutputFileName);
String outputFolderName = Path.Combine(Path.GetDirectoryName(OutputFileName), "7zip");
Log.LogMessage("Downloading 7zip ...");
WebClient webClient = new WebClient();
webClient.DownloadFile("http://www.7-zip.org/a/7za920.zip", OutputFileName);
ZipFile.ExtractToDirectory(OutputFileName, outputFolderName);
File.Delete(OutputFileName);
Log.LogMessage("Downloaded 7zip!");
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
38 changes: 5 additions & 33 deletions Build/Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project ToolsVersion="4.0" DefaultTargets="RunAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildProjectDirectory)\Build.tasks" />
<Import Project="$(MsBuildThisFileDirectory)\nuget.targets" />
<Import Project="$(MsBuildThisFileDirectory)\7zip.targets" />

<PropertyGroup>
<Configuration Condition="$(Configuration) == ''">Debug</Configuration>
Expand Down Expand Up @@ -37,9 +38,7 @@
<Target Name="UpdateVersion" Condition="'$(BUILD_NUMBER)' != ''">
<RegexTransform Items="@(RegexTransform)" />
</Target>

<Target Name="RunAll" DependsOnTargets="UpdateVersion; RestorePackages; Build; ReportFxCopResults; RunTests; BuildSites; BuildZips; CopySymbols; BuildNuget" />

<Target Name="RunAll" DependsOnTargets="UpdateVersion; Ensure7Zip; RestorePackages; Build; ReportFxCopResults; RunTests; BuildSites; BuildZips; CopySymbols; BuildNuget" />
<Target Name="CreateOutputPath">
<MakeDir Directories="$(ArtifactsPath)\symbols" Condition="!Exists('$(ArtifactsPath)\symbols')" />
<MakeDir Directories="$(TestResultsPath)" Condition="!Exists('$(TestResultsPath)')" />
Expand Down Expand Up @@ -100,41 +99,14 @@
<PropertyGroup>
<SourceDirectory>$(ArtifactsPath)\SiteExtensions</SourceDirectory>
<ZipTargetPath>$(ArtifactsPath)\zip</ZipTargetPath>
<Exe7Zip>$(MsBuildThisFileDirectory)\7zip\7za.exe</Exe7Zip>
</PropertyGroup>
<RemoveDir Directories="$(ZipTargetPath)" Condition=" Exists('$(ZipTargetPath)') " />
<MakeDir Directories="$(ZipTargetPath)" />
<CreateZipFileFromDirectory
DestinationArchive="$(ZipTargetPath)\Kudu.zip"
SourceDirectory="$(SourceDirectory)"
IncludeBaseDirectory="true" />
<!-- 7Zip doesn`t have slient mode, write log into a file to avoid printing too much text onto screen -->
<Exec Command="$(Exe7Zip) a -y -r &quot;$(ZipTargetPath)\Kudu.zip&quot; &quot;$(ArtifactsPath)\SiteExtensions&quot; &gt; &quot;$(ZipTargetPath)\Kudu.zip.log&quot;" />
<Copy SourceFiles="$(ProjectRoot)\Setup\DeployPrivateKudu.cmd" DestinationFiles="$(ZipTargetPath)\DeployPrivateKudu.cmd" SkipUnchangedFiles="true" />
</Target>

<!-- From https://github.com/sayedihashimi/slow-cheetah/blob/7681c20d9c1796b3628702b3e1288cc6c47884d1/.nuget/NuGet.targets#L101-L105 -->
<PropertyGroup Condition=" '$(ls-msbuildtasks-path)'=='' ">
<ls-msbuildtasks-path>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll</ls-msbuildtasks-path>
<ls-msbuildtasks-path Condition=" !Exists('$(ls-msbuildtasks-path)')">$(MSBuildFrameworkToolsPath)\Microsoft.Build.Tasks.v4.0.dll</ls-msbuildtasks-path>
<ls-msbuildtasks-path Condition=" !Exists('$(ls-msbuildtasks-path)')">$(windir)\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll</ls-msbuildtasks-path>
</PropertyGroup>

<UsingTask TaskName="CreateZipFileFromDirectory" TaskFactory="CodeTaskFactory" AssemblyFile="$(ls-msbuildtasks-path)">
<ParameterGroup>
<DestinationArchive ParameterType="System.String" Required="true"/>
<SourceDirectory ParameterType="System.String" Required="true" />
<IncludeBaseDirectory ParameterType="System.Boolean" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="$(ls-msbuildtasks-path)\..\System.IO.Compression.dll"/>
<Reference Include="$(ls-msbuildtasks-path)\..\System.IO.Compression.FileSystem.dll"/>
<Using Namespace="System.IO" />
<Using Namespace="System.IO.Compression" />
<Code Type="Fragment" Language="cs">
<![CDATA[
ZipFile.CreateFromDirectory(SourceDirectory, DestinationArchive, System.IO.Compression.CompressionLevel.Optimal, IncludeBaseDirectory);
]]>
</Code>
</Task>
</UsingTask>

<Target Name="BuildNuget" Condition="'$(BUILD_NUMBER)' != ''">
<PropertyGroup>
Expand Down

0 comments on commit da3e64c

Please sign in to comment.