Skip to content

Instantly share code, notes, and snippets.

@abock
Created March 25, 2018 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abock/14b10a5d3c00ab6be3aa1dcc5f601066 to your computer and use it in GitHub Desktop.
Save abock/14b10a5d3c00ab6be3aa1dcc5f601066 to your computer and use it in GitHub Desktop.
From 7b7e8b679a0b96cc5a09dbd74d73561d932a33b3 Mon Sep 17 00:00:00 2001
From: Aaron Bockover <abock@microsoft.com>
Date: Sun, 25 Mar 2018 13:50:50 -0400
Subject: [PATCH] slngen
---
CoreBuild.proj | 3 +-
build/Xamarin.Build/MSBuild/GenerateSolution.cs | 76 +++++++++++++++++++++++++
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/CoreBuild.proj b/CoreBuild.proj
index 438342f..eb9ec2b 100644
--- a/CoreBuild.proj
+++ b/CoreBuild.proj
@@ -177,8 +177,7 @@
Name="GenerateSolution"
DependsOnTargets="ComputeSolution"
BeforeTargets="Restore;Build"
- Inputs="$(MSBuildThisFileFullPath)"
- Outputs="$(SolutionFile)">
+>
<ItemGroup>
<SolutionProjects Include="@(ProjectsToBuild -> '$(MSBuildThisFileDirectory)%(Identity)')">
<RelativePath>$([MSBuild]::MakeRelative($(SolutionBasePath), $(MSBuildThisFileDirectory)%(Identity)))</RelativePath>
diff --git a/build/Xamarin.Build/MSBuild/GenerateSolution.cs b/build/Xamarin.Build/MSBuild/GenerateSolution.cs
index ae43f7c..2112a66 100644
--- a/build/Xamarin.Build/MSBuild/GenerateSolution.cs
+++ b/build/Xamarin.Build/MSBuild/GenerateSolution.cs
@@ -9,11 +9,15 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Security.Cryptography;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
+using Microsoft.Build.Construction;
+using Microsoft.Build.Evaluation;
+
namespace Xamarin.MSBuild
{
public sealed class GenerateSolution : Task
@@ -46,10 +50,43 @@ namespace Xamarin.MSBuild
=> string.Equals (Name, other?.Name, StringComparison.OrdinalIgnoreCase);
}
+ static readonly Guid namespaceGuid = Guid.Parse ("6f68575f-1fe1-4249-a8cc-31e8407b72e6");
+
public override bool Execute ()
{
Directory.CreateDirectory (Path.GetDirectoryName (OutputFile));
+ var projects = new ProjectCollection ();
+
+ void LoadProject (string path)
+ {
+ var project = projects.LoadProject (path);
+ foreach (var projectReference in project.GetItems ("ProjectReference")) {
+ var referencePath = Path.GetFullPath (Path.Combine (
+ project.DirectoryPath,
+ projectReference.EvaluatedInclude));
+ if (!projects.GetLoadedProjects (referencePath).Any ())
+ LoadProject (referencePath);
+ }
+ }
+
+ foreach (var project in Projects)
+ LoadProject (project.ItemSpec);
+
+ foreach (var project in projects.LoadedProjects) {
+ var baseUri = new Uri (Path.GetFullPath (OutputFile));
+ var projectUri = new Uri (Path.GetFullPath (project.FullPath));
+ var relativePath = baseUri.MakeRelativeUri (projectUri).OriginalString;
+ var projectGuid = CreateVersion5Guid (namespaceGuid, relativePath);
+ Console.WriteLine ("{0} = {1}", projectGuid,relativePath);
+ }
+
+ return false;
+
+ // Projects
+
+
+
var previousSolutionProjects = MSBuildProjectFile
.ParseProjectsInSolution (OutputFile)
.ToDictionary (project => project.SolutionRelativePath);
@@ -185,5 +222,44 @@ namespace Xamarin.MSBuild
writer.WriteLine ("EndGlobal");
}
+
+ static Guid CreateVersion5Guid (Guid namespaceGuid, string name)
+ {
+ if (name == null)
+ throw new ArgumentNullException (nameof (name));
+
+ using (var sha1 = SHA1.Create ()) {
+ var namespaceBytes = namespaceGuid.ToByteArray ();
+ var nameBytes = Encoding.UTF8.GetBytes (name);
+ Swap (namespaceBytes);
+
+ sha1.TransformBlock (namespaceBytes, 0, namespaceBytes.Length, null, 0);
+ sha1.TransformFinalBlock (nameBytes, 0, nameBytes.Length);
+
+ var guid = new byte [16];
+ Array.Copy (sha1.Hash, 0, guid, 0, 16);
+
+ guid [6] = (byte)((guid [6] & 0x0F) | 0x50);
+ guid [8] = (byte)((guid [8] & 0x3F) | 0x80);
+
+ Swap (guid);
+ return new Guid (guid);
+ }
+
+ void Swap (byte [] g)
+ {
+ void SwapAt (int left, int right)
+ {
+ var t = g [left];
+ g [left] = g [right];
+ g [right] = t;
+ }
+
+ SwapAt (0, 3);
+ SwapAt (1, 2);
+ SwapAt (4, 5);
+ SwapAt (6, 7);
+ }
+ }
}
}
\ No newline at end of file
--
2.11.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment