Skip to content

Commit

Permalink
GetTargetsLocation: throw if not found
Browse files Browse the repository at this point in the history
Throws a DirectoryNotFoundException if the build directory is not found.
Fixes dotnet#1733.
  • Loading branch information
yecril71pl committed Dec 13, 2021
1 parent cff8557 commit 3c43743
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/dotnet-aspnet-codegenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,21 @@ private IProjectContext GetProjectInformation(string projectPath, string configu

private string GetTargetsLocation()
{
const string build = "build";
var assembly = typeof(Program).GetTypeInfo().Assembly;
var path = Path.GetDirectoryName(assembly.Location);
// Crawl up from assembly location till we find 'build' directory.
do
{
if (Directory.EnumerateDirectories(path, "build", SearchOption.TopDirectoryOnly).Any())
if (Directory.EnumerateDirectories(path, build, SearchOption.TopDirectoryOnly).Any())
{
return path;
}

path = Path.GetDirectoryName(path);
} while (path != null);


return string.Empty;
throw new DirectoryNotFoundException(string.Format(Resources .TargetDirectoryNotFound, build));
}

private int Build(ILogger logger, string projectPath, string configuration, string shortFramework, string buildBasePath)
Expand Down

0 comments on commit 3c43743

Please sign in to comment.