Fix overlapping VC++ and CSharp projects in Visual Studio solution

This commit is contained in:
Wojtek Figat
2022-09-12 20:17:52 +02:00
parent c62efdc44a
commit a006fcec40
6 changed files with 21 additions and 14 deletions

View File

@@ -229,7 +229,7 @@ namespace Flax.Build
var project = mainProject = generator.CreateProject();
if (targets[0].CustomExternalProjectFilePath == null)
project.Type = TargetType.NativeCpp;
project.Name = projectName;
project.Name = project.BaseName = projectName;
project.Targets = targets;
project.SearchPaths = new string[0];
project.WorkspaceRootPath = projectInfo.ProjectFolderPath;
@@ -368,7 +368,9 @@ namespace Flax.Build
// Create project description
var project = dotNetProjectGenerator.CreateProject();
project.Type = TargetType.DotNet;
project.Name = binaryModuleName;
project.Name = project.BaseName = binaryModuleName;
if (mainSolutionProject != null && projectInfo == rootProject)
project.Name += ".CSharp"; // Prevent overlapping name with native code project
project.OutputType = TargetOutputType.Library;
project.Targets = targets;
project.SearchPaths = new string[0];
@@ -424,7 +426,7 @@ namespace Flax.Build
!string.IsNullOrEmpty(dependencyModule.BinaryModuleName) &&
dependencyModule.BinaryModuleName != binaryModule.Key)
{
var dependencyProject = projects.Find(x => x != null && x.Generator.Type == project.Generator.Type && x.Name == dependencyModule.BinaryModuleName);
var dependencyProject = projects.Find(x => x != null && x.Generator.Type == project.Generator.Type && x.BaseName == dependencyModule.BinaryModuleName);
if (dependencyProject != null)
{
// Reference that project
@@ -479,7 +481,7 @@ namespace Flax.Build
{
project = dotNetProjectGenerator.CreateProject();
project.Type = TargetType.DotNet;
project.Name = rulesProjectName;
project.Name = project.BaseName = rulesProjectName;
project.Targets = new[] { target };
project.SearchPaths = new string[0];
project.WorkspaceRootPath = workspaceRoot;

View File

@@ -17,6 +17,11 @@ namespace Flax.Build.Projects
/// </summary>
public ProjectGenerator Generator;
/// <summary>
/// The project base name (might not be unique within solution - eg. Name = BaseName + '.CSharp' to prevent overlaps).
/// </summary>
public string BaseName;
/// <summary>
/// The project name.
/// </summary>

View File

@@ -75,8 +75,8 @@ namespace Flax.Build.Projects.VisualStudio
default: throw new ArgumentOutOfRangeException();
}
csProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", project.Name));
csProjectFileContent.AppendLine(string.Format(" <AssemblyName>{0}.CSharp</AssemblyName>", project.Name));
csProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", project.BaseName));
csProjectFileContent.AppendLine(string.Format(" <AssemblyName>{0}.CSharp</AssemblyName>", project.BaseName));
csProjectFileContent.AppendLine(string.Format(" <TargetFrameworkVersion>{0}</TargetFrameworkVersion>", "v4.5.2"));
csProjectFileContent.AppendLine(" <LangVersion>7.3</LangVersion>");
csProjectFileContent.AppendLine(" <FileAlignment>512</FileAlignment>");
@@ -118,7 +118,7 @@ namespace Flax.Build.Projects.VisualStudio
csProjectFileContent.AppendLine(" <AllowUnsafeBlocks>true</AllowUnsafeBlocks>");
if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings)
csProjectFileContent.AppendLine(" <NoWarn>1591</NoWarn>");
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.Name));
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.BaseName));
csProjectFileContent.AppendLine(" <UseVSHostingProcess>true</UseVSHostingProcess>");
csProjectFileContent.AppendLine(" </PropertyGroup>");
}
@@ -149,7 +149,7 @@ namespace Flax.Build.Projects.VisualStudio
csProjectFileContent.AppendLine(" <AllowUnsafeBlocks>true</AllowUnsafeBlocks>");
if (configuration.TargetBuildOptions.ScriptingAPI.IgnoreMissingDocumentationWarnings)
csProjectFileContent.AppendLine(" <NoWarn>1591</NoWarn>");
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.Name));
csProjectFileContent.AppendLine(string.Format(" <DocumentationFile>{0}\\{1}.CSharp.xml</DocumentationFile>", outputPath, project.BaseName));
csProjectFileContent.AppendLine(" <UseVSHostingProcess>true</UseVSHostingProcess>");
csProjectFileContent.AppendLine(" </PropertyGroup>");
}
@@ -174,7 +174,7 @@ namespace Flax.Build.Projects.VisualStudio
{
csProjectFileContent.AppendLine(string.Format(" <ProjectReference Include=\"{0}\">", Utilities.MakePathRelativeTo(dependency.Path, projectDirectory)));
csProjectFileContent.AppendLine(string.Format(" <Project>{0}</Project>", ((VisualStudioProject)dependency).ProjectGuid.ToString("B").ToUpperInvariant()));
csProjectFileContent.AppendLine(string.Format(" <Name>{0}</Name>", dependency.Name));
csProjectFileContent.AppendLine(string.Format(" <Name>{0}</Name>", dependency.BaseName));
csProjectFileContent.AppendLine(" </ProjectReference>");
}

View File

@@ -97,7 +97,7 @@ namespace Flax.Build.Projects.VisualStudio
// Globals
vcProjectFileContent.AppendLine(" <PropertyGroup Label=\"Globals\">");
vcProjectFileContent.AppendLine(string.Format(" <ProjectGuid>{0}</ProjectGuid>", vsProject.ProjectGuid.ToString("B").ToUpperInvariant()));
vcProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", project.Name));
vcProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", project.BaseName));
vcProjectFileContent.AppendLine(string.Format(" <PlatformToolset>{0}</PlatformToolset>", projectFilePlatformToolsetVersion));
vcProjectFileContent.AppendLine(string.Format(" <MinimumVisualStudioVersion>{0}</MinimumVisualStudioVersion>", projectFileToolVersion));
vcProjectFileContent.AppendLine(" <TargetRuntime>Native</TargetRuntime>");

View File

@@ -40,7 +40,7 @@ namespace Flax.Build.Projects.VisualStudio
vcProjectFileContent.AppendLine(" </ItemGroup>");
vcProjectFileContent.AppendLine(" <PropertyGroup Label=\"Globals\">");
vcProjectFileContent.AppendLine(string.Format(" <ProjectGuid>{0}</ProjectGuid>", ProjectGuid.ToString("B").ToUpperInvariant()));
vcProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", Name));
vcProjectFileContent.AppendLine(string.Format(" <RootNamespace>{0}</RootNamespace>", BaseName));
vcProjectFileContent.AppendLine(string.Format(" <MinimumVisualStudioVersion>{0}</MinimumVisualStudioVersion>", projectFileToolVersion));
vcProjectFileContent.AppendLine(string.Format(" <AndroidAPILevel>{0}</AndroidAPILevel>", Configuration.AndroidPlatformApi));
vcProjectFileContent.AppendLine(string.Format(" <AndroidSupportedAbis>{0}</AndroidSupportedAbis>", "arm64-v8a"));
@@ -556,7 +556,7 @@ namespace Flax.Build.Projects.VisualStudio
targetsSorted.Sort((a, b) => b.Platforms.Length.CompareTo(a.Platforms.Length));
var target = targetsSorted.First(x => x.Platforms.Contains(TargetPlatform.Android));
project.Type = TargetType.NativeCpp;
project.Name = "Android";
project.Name = project.BaseName = "Android";
project.Targets = new Target[0];
project.SearchPaths = new string[0];
project.WorkspaceRootPath = rootProject.ProjectFolderPath;

View File

@@ -340,7 +340,7 @@ namespace Flax.Build.Projects.VisualStudioCode
}
break;
case TargetPlatform.Linux:
if (configuration.Platform == TargetPlatform.Linux && (outputType != TargetOutputType.Executable || project.Name == "Flax") && configuration.Name.StartsWith("Editor."))
if (configuration.Platform == TargetPlatform.Linux && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor."))
{
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor"));
}
@@ -388,7 +388,7 @@ namespace Flax.Build.Projects.VisualStudioCode
}
break;
case TargetPlatform.Mac:
if (configuration.Platform == TargetPlatform.Mac && (outputType != TargetOutputType.Executable || project.Name == "Flax") && configuration.Name.StartsWith("Editor."))
if (configuration.Platform == TargetPlatform.Mac && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor."))
{
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Mac", configuration.ConfigurationName, "FlaxEditor"));
}