48 lines
No EOL
1.7 KiB
C#
48 lines
No EOL
1.7 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using Sharpmake;
|
|
|
|
namespace JustDance.Tools.Helpers
|
|
{
|
|
/// <summary>
|
|
/// Allows to merge a project into another one instead of only depending on it.
|
|
///
|
|
/// When used, this reduces the number of projects in the solution but keeps them separated on disk.
|
|
/// </summary>
|
|
public static class ProjectMerger
|
|
{
|
|
public static void MergeDependency<TDependency>(this BaseProject project)
|
|
where TDependency : BaseProject, new()
|
|
{
|
|
var dependency = new TDependency();
|
|
var dependencySourceRoot = dependency.ResolveString(dependency.SourceRootPath);
|
|
project.AdditionalSourceRootPaths.Add(dependencySourceRoot);
|
|
|
|
foreach (var additionalDependency in dependency.AdditionalSourceRootPaths)
|
|
{
|
|
var resolved = dependency.ResolveString(additionalDependency);
|
|
if (!project.AdditionalSourceRootPaths.Contains(resolved))
|
|
{
|
|
project.AdditionalSourceRootPaths.Add(resolved);
|
|
}
|
|
}
|
|
|
|
var assemblyInfo = Util.DirectoryGetFiles(dependencySourceRoot, "*AssemblyInfo.cs", SearchOption.AllDirectories).FirstOrDefault();
|
|
if (assemblyInfo != null)
|
|
{
|
|
project.SourceFilesExclude.Add(assemblyInfo);
|
|
}
|
|
|
|
project.Configuring += (configuration, target) =>
|
|
{
|
|
// Adds the dependencies from the external project.
|
|
var otherDependencies = new Project.Configuration();
|
|
dependency.ConfigureAll(otherDependencies, target);
|
|
|
|
configuration.ReferencesByName.AddRange(otherDependencies.ReferencesByName);
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
} |