mirror of https://github.com/dotnet/tye.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.9 KiB
54 lines
1.9 KiB
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace Microsoft.DotNet.Watcher.Internal
|
|
{
|
|
internal class MsBuildProjectFinder
|
|
{
|
|
/// <summary>
|
|
/// Finds a compatible MSBuild project.
|
|
/// <param name="searchBase">The base directory to search</param>
|
|
/// <param name="project">The filename of the project. Can be null.</param>
|
|
/// </summary>
|
|
public static string FindMsBuildProject(string searchBase, string project)
|
|
{
|
|
var projectPath = project ?? searchBase;
|
|
|
|
if (!Path.IsPathRooted(projectPath))
|
|
{
|
|
projectPath = Path.Combine(searchBase, projectPath);
|
|
}
|
|
|
|
if (Directory.Exists(projectPath))
|
|
{
|
|
var projects = Directory.EnumerateFileSystemEntries(projectPath, "*.*proj", SearchOption.TopDirectoryOnly)
|
|
.Where(f => !".xproj".Equals(Path.GetExtension(f), StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
|
|
if (projects.Count > 1)
|
|
{
|
|
throw new FileNotFoundException($"The project file '{projectPath}' does not exist.");
|
|
}
|
|
|
|
if (projects.Count == 0)
|
|
{
|
|
throw new FileNotFoundException($"Could not find a MSBuild project file in '{projectPath}'. Specify which project to use with the --project option.");
|
|
}
|
|
|
|
return projects[0];
|
|
}
|
|
|
|
if (!File.Exists(projectPath))
|
|
{
|
|
throw new FileNotFoundException($"The project file '{projectPath}' does not exist.");
|
|
}
|
|
|
|
return projectPath;
|
|
}
|
|
}
|
|
}
|
|
|