diff --git a/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs b/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs index 99c4ec6ec..2bdfbe2ba 100644 --- a/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs +++ b/src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs @@ -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); } } diff --git a/src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs b/src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs index 5319e4b97..6ba842bc6 100644 --- a/src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs +++ b/src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs @@ -31,16 +31,19 @@ public static void EnsureDotnet() /// e.g. in Directory.Build.props /// /// Directory containing the .csproj file + /// Name of the .csproj file /// Target framework, e.g. net8.0 /// - public static async Task DetermineTargetFramework(string projectDirectory) + public static async Task 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",