Permalink
Browse files

Update to use 7zip to create Kudu.zip

  • Loading branch information...
Xiaomin Wu
Xiaomin Wu committed May 13, 2016
1 parent 09c4a18 commit da3e64c4f96fd3469011542f54f89d6da90fdb76
Showing with 71 additions and 34 deletions.
  1. +2 −1 .gitignore
  2. +64 −0 Build/7zip.targets
  3. +5 −33 Build/Build.proj
View
@@ -25,4 +25,5 @@ nuget.exe
Kudu.Services.Web/commit.txt
Setup/WebPiCmdSetup.log
Kudu.Services.Web/node_modules/
.vs/
.vs/
Build/7zip/
View
@@ -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>
View
@@ -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>
@@ -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)')" />
@@ -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>

0 comments on commit da3e64c

Please sign in to comment.