Fix Visual Studio project GUIDs getting randomized during regeneration
This commit is contained in:
@@ -228,6 +228,8 @@ namespace Flax.Build
|
||||
var projectToModulesBuildOptions = new Dictionary<Project, Dictionary<Module, BuildOptions>>();
|
||||
Project mainSolutionProject = null;
|
||||
ProjectGenerator nativeProjectGenerator = ProjectGenerator.Create(projectFormat, TargetType.NativeCpp);
|
||||
var solutionName = rootProject.Name;
|
||||
var solutionPath = Path.Combine(workspaceRoot, solutionName + '.' + nativeProjectGenerator.SolutionFileExtension);
|
||||
|
||||
// Group targets by project name and sort groups based on the project (ensures that referenced plugin source projects are generated firstly before main source projects)
|
||||
var targetGroups = new List<ProjectTargetsGroup>();
|
||||
@@ -549,7 +551,7 @@ namespace Flax.Build
|
||||
foreach (var project in projects)
|
||||
{
|
||||
Log.Verbose(project.Name + " -> " + project.Path);
|
||||
project.Generate();
|
||||
project.Generate(solutionPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +630,7 @@ namespace Flax.Build
|
||||
using (new ProfileEventScope("GenerateProject"))
|
||||
{
|
||||
Log.Verbose("Project " + rulesProjectName + " -> " + project.Path);
|
||||
dotNetProjectGenerator.GenerateProject(project);
|
||||
dotNetProjectGenerator.GenerateProject(project, solutionPath);
|
||||
}
|
||||
|
||||
projects.Add(project);
|
||||
@@ -641,9 +643,9 @@ namespace Flax.Build
|
||||
using (new ProfileEventScope("CreateSolution"))
|
||||
{
|
||||
solution = nativeProjectGenerator.CreateSolution();
|
||||
solution.Name = rootProject.Name;
|
||||
solution.Name = solutionName;
|
||||
solution.WorkspaceRootPath = workspaceRoot;
|
||||
solution.Path = Path.Combine(workspaceRoot, solution.Name + '.' + nativeProjectGenerator.SolutionFileExtension);
|
||||
solution.Path = solutionPath;
|
||||
solution.Projects = projects.ToArray();
|
||||
solution.MainProject = mainSolutionProject;
|
||||
}
|
||||
|
||||
@@ -253,9 +253,9 @@ namespace Flax.Build.Projects
|
||||
/// <summary>
|
||||
/// Generates the project.
|
||||
/// </summary>
|
||||
public virtual void Generate()
|
||||
public virtual void Generate(string solutionPath)
|
||||
{
|
||||
Generator.GenerateProject(this);
|
||||
Generator.GenerateProject(this, solutionPath);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Flax.Build.Projects
|
||||
/// Generates the project.
|
||||
/// </summary>
|
||||
/// <param name="project">The project.</param>
|
||||
public abstract void GenerateProject(Project project);
|
||||
public abstract void GenerateProject(Project project, string solutionPath);
|
||||
|
||||
/// <summary>
|
||||
/// Generates the solution.
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
public override TargetType? Type => TargetType.DotNet;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
public override void GenerateProject(Project project, string solutionPath)
|
||||
{
|
||||
var csProjectFileContent = new StringBuilder();
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
if (vsProject.CSharp.UseFlaxVS && VisualStudioInstance.HasFlaxVS)
|
||||
projectTypes = ProjectTypeGuids.ToOption(ProjectTypeGuids.FlaxVS) + ';' + projectTypes;
|
||||
|
||||
// Try to reuse the existing project guid from solution file
|
||||
vsProject.ProjectGuid = GetProjectGuid(solutionPath, vsProject.Name);
|
||||
if (vsProject.ProjectGuid == Guid.Empty)
|
||||
vsProject.ProjectGuid = Guid.NewGuid();
|
||||
|
||||
// Header
|
||||
|
||||
csProjectFileContent.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
public override TargetType? Type => TargetType.DotNetCore;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
public override void GenerateProject(Project project, string solutionPath)
|
||||
{
|
||||
var csProjectFileContent = new StringBuilder();
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
}
|
||||
}
|
||||
|
||||
// Try to reuse the existing project guid from solution file
|
||||
vsProject.ProjectGuid = GetProjectGuid(solutionPath, vsProject.Name);
|
||||
if (vsProject.ProjectGuid == Guid.Empty)
|
||||
vsProject.ProjectGuid = Guid.NewGuid();
|
||||
|
||||
// Header
|
||||
csProjectFileContent.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
|
||||
csProjectFileContent.AppendLine("");
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
public override void GenerateProject(Project project, string solutionPath)
|
||||
{
|
||||
var vcProjectFileContent = new StringBuilder();
|
||||
var vcFiltersFileContent = new StringBuilder();
|
||||
@@ -67,6 +67,13 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
var projectDirectory = Path.GetDirectoryName(project.Path);
|
||||
var filtersDirectory = project.SourceFolderPath;
|
||||
|
||||
// Try to reuse the existing project guid from existing files
|
||||
vsProject.ProjectGuid = GetProjectGuid(vsProject.Path, vsProject.Name);
|
||||
if (vsProject.ProjectGuid == Guid.Empty)
|
||||
vsProject.ProjectGuid = GetProjectGuid(solutionPath, vsProject.Name);
|
||||
if (vsProject.ProjectGuid == Guid.Empty)
|
||||
vsProject.ProjectGuid = Guid.NewGuid();
|
||||
|
||||
// Header
|
||||
vcProjectFileContent.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
vcProjectFileContent.AppendLine(string.Format("<Project DefaultTargets=\"Build\" ToolsVersion=\"{0}\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", projectFileToolVersion));
|
||||
|
||||
@@ -36,20 +36,5 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Path
|
||||
{
|
||||
get => base.Path;
|
||||
set
|
||||
{
|
||||
base.Path = value;
|
||||
|
||||
if (ProjectGuid == Guid.Empty)
|
||||
{
|
||||
ProjectGuid = VisualStudioProjectGenerator.GetProjectGuid(Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
public override Guid ProjectTypeGuid => ProjectTypeGuids.Android;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Generate()
|
||||
public override void Generate(string solutionPath)
|
||||
{
|
||||
var gen = (VisualStudioProjectGenerator)Generator;
|
||||
var projectFileToolVersion = gen.ProjectFileToolVersion;
|
||||
@@ -141,9 +141,10 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>The project ID.</returns>
|
||||
public static Guid GetProjectGuid(string path)
|
||||
public static Guid GetProjectGuid(string path, string projectName)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
// Look up for the guid in VC++-project file
|
||||
if (File.Exists(path) && Path.GetExtension(path).Equals(".vcxproj", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -161,8 +162,25 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
// Hide errors
|
||||
}
|
||||
}
|
||||
if (File.Exists(path) && Path.GetExtension(path).Equals(".sln", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
Regex projectRegex = new Regex(@"Project\(.*\) = \""(\S+)\"", \""(\S+)\"", \""{(\S+)}\""");
|
||||
MatchCollection matches = projectRegex.Matches(File.ReadAllText(path));
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
if (matches[i].Groups[1].Value == projectName)
|
||||
return Guid.ParseExact(matches[i].Groups[3].Value, "D");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Hide errors
|
||||
}
|
||||
}
|
||||
|
||||
return Guid.NewGuid();
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -250,7 +268,7 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
}
|
||||
}
|
||||
|
||||
// Try to extract info from the existing solution file to make random IDs stable
|
||||
// Try to extract solution folder info from the existing solution file to make random IDs stable
|
||||
var solutionId = Guid.NewGuid();
|
||||
var folderIds = new Dictionary<string, Guid>();
|
||||
if (File.Exists(solution.Path))
|
||||
@@ -266,16 +284,12 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
solutionId = Guid.ParseExact(value.Substring(15), "B");
|
||||
}
|
||||
|
||||
var folderIdsMatch = Regex.Match(contents, "Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"(.*?)\", \"(.*?)\", \"{(.*?)}\"");
|
||||
if (folderIdsMatch.Success)
|
||||
var folderIdMatches = new Regex("Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"(.*?)\", \"(.*?)\", \"{(.*?)}\"").Matches(contents);
|
||||
foreach (Match match in folderIdMatches)
|
||||
{
|
||||
foreach (Capture capture in folderIdsMatch.Captures)
|
||||
{
|
||||
var value = capture.Value.Substring("Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"".Length);
|
||||
var folder = value.Substring(0, value.IndexOf('\"'));
|
||||
var folderId = Guid.ParseExact(value.Substring(folder.Length * 2 + "\", \"".Length + "\", \"".Length, 38), "B");
|
||||
folderIds["Source\\" + folder] = folderId;
|
||||
}
|
||||
var folder = match.Groups[1].Value;
|
||||
var folderId = Guid.ParseExact(match.Groups[3].Value, "D");
|
||||
folderIds[folder] = folderId;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Flax.Build.Projects.VisualStudioCode
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
public override void GenerateProject(Project project, string solutionPath)
|
||||
{
|
||||
// Not used, solution contains all projects definitions
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Flax.Build.Projects
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProject(Project project)
|
||||
public override void GenerateProject(Project project, string solutionPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user