private ISiteBuilder ResolveProject(string repositoryRoot, string targetPath, bool tryWebSiteProject, SearchOption searchOption = SearchOption.AllDirectories, bool specificConfiguration = true)
{
if (DeploymentHelper.IsProject(targetPath))
{
return(DetermineProject(repositoryRoot, targetPath));
}
// Check for loose projects
var projects = DeploymentHelper.GetProjects(targetPath, searchOption);
if (projects.Count > 1)
{
// Can't determine which project to build
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
Resources.Error_AmbiguousProjects,
String.Join(", ", projects)));
}
else if (projects.Count == 1)
{
return(DetermineProject(repositoryRoot, projects[0]));
}
if (tryWebSiteProject)
{
// Website projects need a solution to build so look for one in the repository path
// that has this website in it.
var solutions = VsHelper.FindContainingSolutions(repositoryRoot, targetPath);
// More than one solution is ambiguous
if (solutions.Count > 1)
{
ThrowAmbiguousSolutionsError(solutions);
}
else if (solutions.Count == 1)
{
// Unambiguously pick the root
return(new WebSiteBuilder(_propertyProvider,
repositoryRoot,
targetPath,
_environment.TempPath,
_environment.NuGetCachePath,
solutions[0].Path));
}
}
// This should only ever happen if the user specifies an invalid directory.
// The other case where the method is called we always resolve the path so it's a non issue there.
if (specificConfiguration && !Directory.Exists(targetPath))
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
Resources.Error_ProjectDoesNotExist,
targetPath));
}
// If there's none then use the basic builder (the site is xcopy deployable)
return(new BasicBuilder(targetPath, _environment.TempPath, _environment.ScriptPath, _environment.SiteRootPath));
}