CompatTasks.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using static CakeScript.Startup;
  6. using static CakeScript.CakeAPI;
  7. using Cake.Common.IO;
  8. using Cake.Common.Tools.DotNet.MSBuild;
  9. using Cake.Common.Tools.NuGet.Pack;
  10. using Cake.Common.Tools.DotNet.Build;
  11. using Cake.Common.Tools.DotNet;
  12. namespace CakeScript;
  13. partial class Program
  14. {
  15. [DependsOn(nameof(PrepareNuget))]
  16. public void PackCompat()
  17. {
  18. const string packageId = "FastReport.Compat";
  19. string usedPackagesVersionPath = Path.Combine(solutionDirectory, "UsedPackages.version");
  20. string resourcesDir = Path.Combine(solutionDirectory, "Nuget");
  21. string packCopyDir = Path.Combine(resourcesDir, packageId);
  22. string srcDir = Path.Combine(solutionDirectory, "src");
  23. string compatAnyDir = Path.Combine(srcDir, packageId);
  24. string compatAnyProj = Path.Combine(compatAnyDir, packageId + ".csproj");
  25. string compatWinDir = Path.Combine(srcDir, packageId + "-Windows");
  26. string compatWinProj = Path.Combine(compatWinDir, packageId + "-Windows.csproj");
  27. string tmpDir = Path.Combine(solutionDirectory, "tmp");
  28. if (DirectoryExists(tmpDir))
  29. {
  30. DeleteDirectory(tmpDir, new DeleteDirectorySettings
  31. {
  32. Force = true,
  33. Recursive = true
  34. });
  35. }
  36. DotNetClean(compatAnyProj);
  37. DotNetClean(compatWinProj);
  38. var buildSettings = new DotNetBuildSettings
  39. {
  40. Configuration = config,
  41. NoRestore = false,
  42. MSBuildSettings = new DotNetMSBuildSettings
  43. {
  44. Version = version,
  45. }.WithProperty("SolutionDir", solutionDirectory)
  46. .WithProperty("SolutionFileName", solutionFilename)
  47. .WithProperty("BaseOutputPath", tmpDir),
  48. };
  49. DotNetBuild(compatAnyProj, buildSettings);
  50. DotNetBuild(compatWinProj, buildSettings);
  51. string emptyFilePath = Path.Combine(tmpDir, "lib", "netcoreapp3.0", "_._");
  52. Directory.GetParent(emptyFilePath).Create();
  53. File.Create(emptyFilePath).Close();
  54. if (!File.Exists(emptyFilePath))
  55. throw new Exception($"Empty file wasn't created. '{emptyFilePath}'");
  56. // Get used packages version
  57. string SystemDrawingCommonVersion = XmlPeek(usedPackagesVersionPath, "//SystemDrawingCommonVersion/text()");
  58. Information($"System.Drawing.Common version: {SystemDrawingCommonVersion}");
  59. string CodeAnalysisCSharpVersion = XmlPeek(usedPackagesVersionPath, "//CodeAnalysisCSharpVersion/text()");
  60. Information($"Microsoft.CodeAnalysis.CSharp version: {CodeAnalysisCSharpVersion}");
  61. string CodeAnalysisVisualBasicVersion = XmlPeek(usedPackagesVersionPath, "//CodeAnalysisVisualBasicVersion/text()");
  62. Information($"Microsoft.CodeAnalysis.VisualBasic version: {CodeAnalysisVisualBasicVersion}");
  63. var dependencies = new List<NuSpecDependency>();
  64. AddNuSpecDep(null, null, tfmNet40);
  65. // System.Drawing.Common reference doesn't included in net5.0-windows target
  66. AddNuSpecDep("System.Drawing.Common", SystemDrawingCommonVersion, tfmStandard20);
  67. AddNuSpecDep("System.Drawing.Common", SystemDrawingCommonVersion, tfmStandard21);
  68. AddNuSpecDep("System.Drawing.Common", SystemDrawingCommonVersion, tfmCore30);
  69. AddNuSpecDepCore("Microsoft.CodeAnalysis.CSharp", CodeAnalysisCSharpVersion);
  70. AddNuSpecDepCore("Microsoft.CodeAnalysis.VisualBasic", CodeAnalysisVisualBasicVersion);
  71. const string license = "LICENSE.md";
  72. var files = new[] {
  73. new NuSpecContent{Source = Path.Combine(tmpDir, "**", "*.*"), Target = ""},
  74. new NuSpecContent{Source = Path.Combine(packCopyDir, "**", "*.*"), Target = ""},
  75. new NuSpecContent{Source = Path.Combine(solutionDirectory, FRLOGO192PNG), Target = "" },
  76. new NuSpecContent{Source = Path.Combine(solutionDirectory, license), Target = "" },
  77. };
  78. var nuGetPackSettings = new NuGetPackSettings
  79. {
  80. Id = packageId,
  81. Version = version,
  82. Authors = new[] { "Fast Reports Inc." },
  83. Owners = new[] { "Fast Reports Inc." },
  84. Description = "Common compatible types for FastReport .Net, Core and Mono",
  85. Repository = new NuGetRepository { Type = "GIT", Url = "https://github.com/FastReports/FastReport.Compat" },
  86. ProjectUrl = new Uri("https://www.fast-report.com/en/product/fast-report-net"),
  87. Icon = FRLOGO192PNG,
  88. IconUrl = new Uri("https://raw.githubusercontent.com/FastReports/FastReport.Compat/master/frlogo-big.png"),
  89. ReleaseNotes = new[] { "See the latest changes on https://github.com/FastReports/FastReport.Compat" },
  90. License = new NuSpecLicense { Type = "file", Value = license },
  91. Copyright = "Fast Reports Inc.",
  92. Tags = new[] { "reporting", "reports", "pdf", "html", "mvc", "docx", "xlsx", "Core" },
  93. RequireLicenseAcceptance = true,
  94. Symbols = false,
  95. NoPackageAnalysis = true,
  96. Files = files,
  97. Dependencies = dependencies,
  98. BasePath = tmpDir,
  99. OutputDirectory = outdir
  100. };
  101. // Pack
  102. var template = Path.Combine(resourcesDir, "template.nuspec");
  103. NuGetPack(template, nuGetPackSettings);
  104. // Local functions:
  105. // For Net Standard 2.0, Standard 2.1, Core 3.0 and Net 5.0-windows
  106. void AddNuSpecDepCore(string id, string version)
  107. {
  108. AddNuSpecDep(id, version, tfmStandard20);
  109. AddNuSpecDep(id, version, tfmStandard21);
  110. AddNuSpecDep(id, version, tfmCore30);
  111. AddNuSpecDep(id, version, tfmNet5win7);
  112. }
  113. void AddNuSpecDep(string id, string version, string tfm)
  114. {
  115. dependencies.Add(new NuSpecDependency { Id = id, Version = version, TargetFramework = tfm });
  116. }
  117. }
  118. }