2
0

buildpackages.task 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3. <ImportGroup Label="PropertySheets">
  4. <Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
  5. </ImportGroup>
  6. <UsingTask TaskName="BuildPackagesTask"
  7. TaskFactory="CodeTaskFactory"
  8. AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
  9. <Task>
  10. <Reference Include="Microsoft.Build" />
  11. <Reference Include="Microsoft.Build.Framework" />
  12. <Reference Include="Microsoft.Build.Utilities.Core" />
  13. <Reference Include="System.IO.Compression.FileSystem" />
  14. <Code Type="Class" Language="cs">
  15. <![CDATA[
  16. using System;
  17. using System.IO;
  18. using System.IO.Compression;
  19. using Microsoft.Build.Framework;
  20. using System.Reflection;
  21. using Microsoft.Build.Execution;
  22. using System.Net;
  23. using System.ComponentModel;
  24. using System.Diagnostics;
  25. public class BuildPackagesTask : Microsoft.Build.Utilities.Task
  26. {
  27. private string basedir;
  28. internal static bool FileOrDirectoryExists(string name)
  29. {
  30. return (Directory.Exists(name) || File.Exists(name));
  31. }
  32. internal static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
  33. foreach (DirectoryInfo dir in source.GetDirectories())
  34. CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
  35. foreach (FileInfo file in source.GetFiles())
  36. file.CopyTo(Path.Combine(target.FullName, file.Name));
  37. }
  38. public override bool Execute()
  39. {
  40. basedir = Path.GetFullPath(@"$(BaseDir)");
  41. Log.LogMessage(MessageImportance.High,
  42. "Building packages.");
  43. string package = "signalwire-client-c-$(signalwire-client-cVersion)";
  44. string package_root = @"$(BaseDir)out\packages\" + package + @"-headers\" + package;
  45. if (!FileOrDirectoryExists(package_root))
  46. {
  47. Directory.CreateDirectory(package_root + @"\include");
  48. CopyFilesRecursively(new DirectoryInfo(@"..\inc\"), new DirectoryInfo(package_root + @"\include"));
  49. ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-headers\", @"$(BaseDir)out\" + package + @"-headers.zip".ToLower(), CompressionLevel.Optimal, false);
  50. }
  51. package_root = @"$(BaseDir)out\packages\signalwire-client-c-$(signalwire-client-cVersion)-binaries-$(Platform)-$(Configuration)\" + package;
  52. if (!FileOrDirectoryExists(package_root))
  53. {
  54. Directory.CreateDirectory(package_root + @"\binaries\$(Platform)\$(Configuration)");
  55. string[] files = {"signalwire_client.lib", @"signalwire_client.dll"};
  56. foreach (string f in files) {
  57. File.Copy(@"..\Build-$(Platform)\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
  58. }
  59. if ("$(Configuration.ToLower())" == "debug" ) {
  60. string[] debug_files = {"signalwire_client.pdb"};
  61. foreach (string f in debug_files) {
  62. File.Copy(@"..\Build-$(Platform)\$(Configuration)\" + f, package_root + @"\binaries\$(Platform)\$(Configuration)\" + f);
  63. }
  64. }
  65. ZipFile.CreateFromDirectory(@"$(BaseDir)out\packages\" + package + @"-binaries-$(Platform)-$(Configuration)\", @"$(BaseDir)out\"+ package + @"-binaries-$(Platform)-$(Configuration).zip".ToLower(), CompressionLevel.Optimal, false);
  66. }
  67. return true;
  68. }
  69. }
  70. ]]>
  71. </Code>
  72. </Task>
  73. </UsingTask>
  74. <PropertyGroup>
  75. <buildpackagestask_Imported>true</buildpackagestask_Imported>
  76. </PropertyGroup>
  77. <Target Name="BuildPackagesTarget" AfterTargets="Build">
  78. <BuildPackagesTask />
  79. </Target>
  80. </Project>