Skip to content

Commit

Permalink
Optimize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VineethReyya committed Sep 10, 2024
1 parent 09112e5 commit d9cb60e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,9 @@ private static async Task WriteDockerfile(WorkerRuntime workerRuntime, string la
if (WorkerRuntimeLanguageHelper.IsDotnet(workerRuntime) && string.IsNullOrEmpty(targetFramework))
{
var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory);
string projectFilePath = ProjectHelpers.FindProjectFile(functionAppRoot);
if (projectFilePath != null)
if (functionAppRoot != null)
{
targetFramework = await DotnetHelpers.DetermineTargetFramework(Path.GetDirectoryName(projectFilePath));
targetFramework = await DotnetHelpers.DetermineTargetFramework(functionAppRoot);
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ public static void EnsureDotnet()
/// e.g. in Directory.Build.props
/// </summary>
/// <param name="projectDirectory">Directory containing the .csproj file</param>
/// <param name="projectFilename">Name of the .csproj file</param>
/// <returns>Target framework, e.g. net8.0</returns>
/// <exception cref="CliException"></exception>
public static async Task<string> DetermineTargetFramework(string projectDirectory)
public static async Task<string> DetermineTargetFramework(string projectDirectory, string projectFilename = null)
{
EnsureDotnet();
string projectFilename = null;
var projectFilePath = ProjectHelpers.FindProjectFile(projectDirectory);
if (projectFilePath != null)
if (projectFilename == null)
{
projectFilename = Path.GetFileName(projectFilePath);
var projectFilePath = ProjectHelpers.FindProjectFile(projectDirectory);
if (projectFilePath != null)
{
projectFilename = Path.GetFileName(projectFilePath);
}
}
var exe = new Executable(
"dotnet",
Expand Down

0 comments on commit d9cb60e

Please sign in to comment.