diff --git a/.gitignore b/.gitignore index 6e291ec94d..61c78d0c8b 100644 --- a/.gitignore +++ b/.gitignore @@ -211,5 +211,8 @@ artifacts/ #BenchmarkDotNet **/BenchmarkDotNet.Artifacts/ +# Build process +*.csproj.bak + #CodeCoverage **/CodeCoverage/* \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index a79743393c..6e04dc1df4 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -10,10 +10,10 @@ namespace ConsoleApplication using System.IO; using System.Linq; using System.Text; - + using System.Xml; using LibGit2Sharp; - using Microsoft.DotNet.ProjectModel; - using Newtonsoft.Json; + using Microsoft.Build.Construction; + using Microsoft.Build.Evaluation; using NuGet.Versioning; /// @@ -65,31 +65,29 @@ namespace ConsoleApplication { var resetmode = args.Contains("reset"); - // Find the project root where glbal.json lives - var root = ProjectRootResolver.ResolveRootDirectory("."); + // Find the project root + var root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), "..")); // Lets find the repo var repo = new LibGit2Sharp.Repository(root); // Lets find all the project.json files in the src folder (don't care about versioning `tests`) - var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), Project.FileName, SearchOption.AllDirectories); + var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), "*.csproj", SearchOption.AllDirectories); + + ResetProject(projectFiles); // Open them and convert them to source projects - var projects = projectFiles.Select(x => ProjectReader.GetProject(x)) + var projects = projectFiles.Select(x => ProjectRootElement.Open(x, ProjectCollection.GlobalProjectCollection, true)) .Select(x => new SourceProject(x, repo.Info.WorkingDirectory)) .ToList(); - if (resetmode) - { - ResetProject(projects); - } - else + if (!resetmode) { CaclulateProjectVersionNumber(projects, repo); UpdateVersionNumbers(projects); - CreateBuildScript(projects); + CreateBuildScript(projects, root); foreach (var p in projects) { @@ -98,12 +96,14 @@ namespace ConsoleApplication } } - private static void CreateBuildScript(IEnumerable projects) + private static void CreateBuildScript(IEnumerable projects, string root) { + var outputDir = Path.GetFullPath(Path.Combine(root, @"artifacts\bin\ImageSharp")); + var sb = new StringBuilder(); foreach (var p in projects) { - sb.AppendLine($@"dotnet pack --configuration Release --output ""artifacts\bin\ImageSharp"" ""{p.ProjectFilePath}"""); + sb.AppendLine($@"dotnet pack --configuration Release --output ""{outputDir}"" ""{p.ProjectFilePath}"""); } File.WriteAllText("build-inner.cmd", sb.ToString()); @@ -113,17 +113,17 @@ namespace ConsoleApplication { foreach (var p in projects) { - // TODO force update of all dependent projects to point to the newest build. - // we skip the build number and standard CI prefix on first commits - var newVersion = p.FinalVersionNumber; - // create a backup file so we can rollback later without breaking formatting File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); + } - dynamic projectFile = JsonConvert.DeserializeObject(File.ReadAllText(p.FullProjectFilePath)); + foreach (var p in projects) + { + // TODO force update of all dependent projects to point to the newest build. + // we skip the build number and standard CI prefix on first commits + var newVersion = p.FinalVersionNumber; - projectFile.version = $"{newVersion}-*"; - File.WriteAllText(p.FullProjectFilePath, JsonConvert.SerializeObject(projectFile, Formatting.Indented)); + p.UpdateVersion(newVersion); } } @@ -168,7 +168,7 @@ namespace ConsoleApplication projects.ForEach(x => x.CalculateVersion(repo, branch)); } - private static void ResetProject(List projects) + private static void ResetProject(IEnumerable projectPaths) { if (File.Exists("build-inner.cmd")) { @@ -176,12 +176,12 @@ namespace ConsoleApplication } // revert the project.json change be reverting it but skipp all the git stuff as its not needed - foreach (var p in projects) + foreach (var p in projectPaths) { - if (File.Exists($"{p.FullProjectFilePath}.bak")) + if (File.Exists($"{p}.bak")) { - File.Copy($"{p.FullProjectFilePath}.bak", p.FullProjectFilePath, true); - File.Delete($"{p.FullProjectFilePath}.bak"); + File.Copy($"{p}.bak", p, true); + File.Delete($"{p}.bak"); } } } @@ -192,21 +192,24 @@ namespace ConsoleApplication public class SourceProject { private readonly IEnumerable dependencies; + private readonly ProjectRootElement project; /// /// Initializes a new instance of the class. /// /// The project. /// The root. - public SourceProject(Project project, string root) + public SourceProject(ProjectRootElement project, string root) { - this.Name = project.Name; - this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length); - this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length); - this.FullProjectFilePath = project.ProjectFilePath; - this.Version = project.Version; - this.dependencies = project.Dependencies.Select(x => x.Name); + this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value; + + this.ProjectDirectory = project.DirectoryPath.Substring(root.Length); + this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length); + this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File); + this.Version = new NuGetVersion(project.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); + this.dependencies = project.Items.Where(x => x.ItemType == "ProjectReference").Select(x => Path.GetFullPath(Path.Combine(project.DirectoryPath, x.Include))); this.FinalVersionNumber = this.Version.ToFullString(); + this.project = project; } /// @@ -223,7 +226,7 @@ namespace ConsoleApplication /// /// The version. /// - public NuGetVersion Version { get; } + public NuGetVersion Version { get; private set; } /// /// Gets the dependent projects. @@ -279,7 +282,18 @@ namespace ConsoleApplication /// The projects. public void PopulateDependencies(IEnumerable projects) { - this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.Name)).ToList(); + this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.FullProjectFilePath)).ToList(); + } + + /// + /// Update the version number in the project file + /// + /// the new version number to save. + internal void UpdateVersion(string versionnumber) + { + this.project.AddProperty("VersionPrefix", versionnumber); + this.Version = new NuGetVersion(versionnumber); + this.project.Save(); } /// @@ -334,11 +348,15 @@ namespace ConsoleApplication var blob = repo.Lookup(projectFileChange.Oid); using (var s = blob.GetContentStream()) { - var project = new ProjectReader().ReadProject(s, this.Name, this.FullProjectFilePath, null); - if (project.Version != this.Version) + using (var reader = XmlReader.Create(s)) { - // version changed - return false; + var proj = ProjectRootElement.Create(reader); + var version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); + if (version != this.Version) + { + // version changed + return false; + } } } } diff --git a/build/build.csproj b/build/build.csproj index 38e6415999..49f6489b4f 100644 --- a/build/build.csproj +++ b/build/build.csproj @@ -13,7 +13,7 @@ - + All diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index fc36e7ed5f..d9688f242a 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp.Drawing - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj b/src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj index 9caa41643a..6b741d32cf 100644 --- a/src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj +++ b/src/ImageSharp.Formats.Bmp/ImageSharp.Formats.Bmp.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp.Formats.Bmp - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj b/src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj index 2890e58a83..a7ee625f77 100644 --- a/src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj +++ b/src/ImageSharp.Formats.Gif/ImageSharp.Formats.Gif.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp.Formats.Gif - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj b/src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj index e249c58f21..0b1888c278 100644 --- a/src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj +++ b/src/ImageSharp.Formats.Jpeg/ImageSharp.Formats.Jpeg.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp.Formats.Jpeg - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/src/ImageSharp.Processing/ImageSharp.Processing.csproj b/src/ImageSharp.Processing/ImageSharp.Processing.csproj index cd051d1b80..52794e5b36 100644 --- a/src/ImageSharp.Processing/ImageSharp.Processing.csproj +++ b/src/ImageSharp.Processing/ImageSharp.Processing.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp.Processing - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index da8586a3e2..4ebfb9a4ad 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp - 1.0.0-alpha1 + 1.0.0-alpha2 James Jackson-South and contributors netstandard1.1;net45;net461 true diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 142825c55d..b4bedf8274 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -7,7 +7,7 @@ false - +