2016-10-28 13:39:07 -07:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license info
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-10-28 22:11:13 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2016-10-28 13:39:07 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.DotNet.Internal.ProjectModel;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.ProjectJsonMigration
|
|
|
|
|
{
|
2016-10-31 11:00:43 -07:00
|
|
|
|
internal static class ProjectExtensions
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
2016-10-31 11:00:43 -07:00
|
|
|
|
public static ProjectType GetProjectType(this Project project)
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
ProjectType projectType = ProjectType.Library;
|
|
|
|
|
if (project.IsTestProject)
|
2016-10-28 22:11:13 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
projectType = ProjectType.Test;
|
2016-10-28 22:11:13 -07:00
|
|
|
|
}
|
2016-10-31 16:34:37 -07:00
|
|
|
|
else if (project.HasEntryPoint())
|
2016-10-31 13:59:47 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
if (project.HasDependency(ContainingName(".AspNetCore.")))
|
|
|
|
|
{
|
|
|
|
|
projectType = ProjectType.Web;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
projectType = ProjectType.Console;
|
|
|
|
|
}
|
2016-10-31 13:59:47 -07:00
|
|
|
|
}
|
2016-10-28 22:11:13 -07:00
|
|
|
|
|
|
|
|
|
return projectType;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 16:34:37 -07:00
|
|
|
|
private static bool HasEntryPoint(this Project project)
|
2016-10-28 22:11:13 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
return project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault();
|
|
|
|
|
}
|
2016-10-28 13:39:07 -07:00
|
|
|
|
|
2016-10-31 16:34:37 -07:00
|
|
|
|
private static Func<ProjectLibraryDependency, bool> ContainingName(string nameSegment)
|
|
|
|
|
{
|
|
|
|
|
return x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool HasDependency(this Project project, Func<ProjectLibraryDependency, bool> pred)
|
|
|
|
|
{
|
|
|
|
|
if (HasAnyDependency(project.Dependencies, pred))
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 22:11:13 -07:00
|
|
|
|
foreach (var tf in project.GetTargetFrameworks())
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
if(HasAnyDependency(tf.Dependencies, pred))
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
return true;
|
2016-10-28 13:39:07 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 16:34:37 -07:00
|
|
|
|
return false;
|
2016-10-28 13:39:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 16:34:37 -07:00
|
|
|
|
private static bool HasAnyDependency(
|
|
|
|
|
IEnumerable<ProjectLibraryDependency> dependencies,
|
|
|
|
|
Func<ProjectLibraryDependency, bool> pred)
|
2016-10-28 13:39:07 -07:00
|
|
|
|
{
|
2016-10-31 16:34:37 -07:00
|
|
|
|
return dependencies.Any(pred);
|
2016-10-28 13:39:07 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|