Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
403 stars 166 forks source link

Setting the OutDir in a isolated function causes the build to fail. #2125

Open snarodev opened 7 months ago

snarodev commented 7 months ago

Setting the OutDir option with msbuild causes a Isolated Function build to fail.

How to replicate:

The build then fails. When OutDiris not specified, the extensions.jsonfile is created in the Temp folder and then copied, but when OutDir is specified the extensions.json file is created in the output folder, but then the next step then looks for the file in the .azurefunctions folder.

Example output of the relevant build log parts without the OutDir option (Command msbuild "C:\Users\jms\Desktop\DeleteNow\FunctionApp1\FunctionApp1.sln" -> Build works):

_FunctionsPostBuildCopyFiles:
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\System.Memory.Data.dll" to "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\System.Memory.Data.dll".
_FunctionsPostBuildCopyFiles:
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\System.Net.Http.Formatting.dll" to "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\System.Net.Http.Formatting.dll".
_FunctionsPostBuildCopyFiles:
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\Microsoft.Azure.Functions.Worker.Extensions.pdb" to "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\Microsoft.Azure.Functions.Worker.Extensions.pdb".
_GenerateFunctionsExtensionsMetadataPostBuild:
  Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin" "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\extensions.json"
Done Building Project "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\WorkerExtensions.csproj" (Build target(s)).

_WorkerExtensionsBuildCopy:
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\extensions.json" to "C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\bin\Debug\net6.0\.azurefunctions\extensions.json".
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\Microsoft.Azure.Functions.Worker.Extensions.pdb" to "C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\bin\Debug\net6.0\.azurefunctions\Microsoft.Azure.Functi
  ons.Worker.Extensions.pdb".
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\Microsoft.Azure.WebJobs.Host.Storage.dll" to "C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\bin\Debug\net6.0\.azurefunctions\Microsoft.Azure.WebJobs.Host.
  Storage.dll".
  Copying file from "C:\Users\jms\AppData\Local\Temp\4dqcsfka.vdq\buildout\bin\Microsoft.Azure.Functions.Worker.Extensions.dll" to "C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\bin\Debug\net6.0\.azurefunctions\Microsoft.Azure.Functi
  ons.Worker.Extensions.dll".

Relevant build log part with the OutDir option (Command: msbuild "C:\Users\jms\Desktop\DeleteNow\FunctionApp1\FunctionApp1.sln" /p:OutDir=C:\Users\jms\Desktop\test\test2 -> Build fails):

_FunctionsPostBuildCopyFiles:
Skipping target "_FunctionsPostBuildCopyFiles" because all output files are up-to-date with respect to the input files.
_FunctionsPostBuildCopyFiles:
  Copying file from "C:\Users\jms\Desktop\test\Microsoft.Azure.Functions.Worker.Extensions.pdb" to "C:\Users\jms\Desktop\test\bin\Microsoft.Azure.Functions.Worker.Extensions.pdb".
_GenerateFunctionsExtensionsMetadataPostBuild:
  Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "C:\Users\jms\Desktop\test\bin" "C:\Users\jms\Desktop\test\bin\extensions.json"
Done Building Project "C:\Users\jms\AppData\Local\Temp\ecsgn243.54g\WorkerExtensions.csproj" (Build target(s)).

C:\Users\jms\.nuget\packages\microsoft.azure.functions.worker.sdk\1.15.1\build\Microsoft.Azure.Functions.Worker.Sdk.targets(181,9): error MSB4018: The "EnhanceExtensionsMetadata" task failed unexpectedly. [C:\Users\jms\Desktop\DeleteNow
\LocalFunctionProj\LocalFunctionProj.csproj]
C:\Users\jms\.nuget\packages\microsoft.azure.functions.worker.sdk\1.15.1\build\Microsoft.Azure.Functions.Worker.Sdk.targets(181,9): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\jms\Des
ktop\test\.azurefunctions\extensions.json'. [C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\LocalFunctionProj.csproj]
C:\Users\jms\.nuget\packages\microsoft.azure.functions.worker.sdk\1.15.1\build\Microsoft.Azure.Functions.Worker.Sdk.targets(181,9): error MSB4018:  [C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\LocalFunctionProj.csproj]
C:\Users\jms\.nuget\packages\microsoft.azure.functions.worker.sdk\1.15.1\build\Microsoft.Azure.Functions.Worker.Sdk.targets(181,9): error MSB4018: Server stack trace:  [C:\Users\jms\Desktop\DeleteNow\LocalFunctionProj\LocalFunctionProj.
csproj]
alexander7567 commented 7 months ago

Interesting.. I got the same error while using Azure Pipelines VSBuild:

Done Building Project "C:\Users\VssAdministrator\AppData\Local\Temp\1jdz0xj2.hba\WorkerExtensions.csproj" (Build target(s)).
##[error]C:\Users\VssAdministrator\.nuget\packages\microsoft.azure.functions.worker.sdk\1.16.2\build\Microsoft.Azure.Functions.Worker.Sdk.targets(180,9): Error MSB4018: The "EnhanceExtensionsMetadata" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\a\1\a\.azurefunctions\extensions.json'.

Server stack trace: 
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
   at System.IO.File.ReadAllText(String path)
   at Microsoft.Azure.Functions.Worker.Sdk.Tasks.EnhanceExtensionsMetadata.Execute() in D:\a\_work\1\s\sdk\Sdk\Tasks\EnhanceExtensionsMetadata.cs:line 29
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Build.Framework.ITask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
skmonirul248 commented 7 months ago

Same for me while using Azure Pipelines VSBuild with dotnet-isolated --target-framework net7.0. I tried with Microsoft.Azure.Functions.Worker.Sdk 1.13.0 and 1.16.0

2023-12-06T16:41:22.6632061Z ##[error]C:\Users\VssAdministrator\.nuget\packages\microsoft.azure.functions.worker.sdk\1.16.0\build\Microsoft.Azure.Functions.Worker.Sdk.targets(180,9): Error MSB4018: The "EnhanceExtensionsMetadata" task failed unexpectedly.
System.IO.FileNotFoundException: Could not find file 'D:\a\1\s\Ascend.Functions\bin\Release\net7.0\.azurefunctions\extensions.json'.
File name: 'D:\a\1\s\Ascend.Functions\bin\Release\net7.0\.azurefunctions\extensions.json'
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at Microsoft.Azure.Functions.Worker.Sdk.Tasks.EnhanceExtensionsMetadata.Execute() in D:\a\_work\1\s\sdk\Sdk\Tasks\EnhanceExtensionsMetadata.cs:line 29
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
Mr-Technician commented 5 months ago

Is there any resolution for this issue? I've spent most of today trying to find some resolution for this. I have uninstalled both .NET and Rider, reinstalled them, and tried creating a brand new Functions solution only to be met with this error. I am unable to work on my Functions project with this error.

Mr-Technician commented 5 months ago

I'm not certain what step of the process fixed this issue, but I was able to resolve the error after these steps:

  1. Clear nuget cache
  2. Uninstall Rider
  3. Uninstall Visual Studio
  4. Reboot
  5. Install Visual Studio
  6. Install Rider
  7. Reboot
  8. Attempt to build project (still failed)
  9. Clear nuget cache again
davidpeden3 commented 4 months ago

i ran into what appears to be the same problem but without the involvement of the /p:OutDir parameter.

see https://github.com/Azure/azure-functions-dotnet-worker/issues/2291.

pkpaul5 commented 3 months ago

I am facing the same issue when building function app project targeting .NET 8 in isolated model in Azure DevOps pipeline. The project build fine in local environment but gives this error in Azure DevOps pipeline. I have added steps for installing both .NET 6 and .NET 8 in the ADO pipeline but still facing the same issue. What is the solution to this problem?

Here is the error message : ##[error]C:\Users\VssAdministrator.nuget\packages\microsoft.azure.functions.worker.sdk\1.17.2\build\Microsoft.Azure.Functions.Worker.Sdk.targets(190,9): Error MSB4018: The "EnhanceExtensionsMetadata" task failed unexpectedly. System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\a\1\b\publish_output.azurefunctions\extensions.json'.

markuspalme commented 3 months ago

@pkpaul5 I worked around the problem by not setting an output directory. The build artifacts will then be placed in the default location bin\...\.

pkpaul5 commented 3 months ago

@markuspalme Thanks for your suggestion. I am able to work around the problem by not setting output directory.

jaywar commented 2 months ago

I was able to build in Azure Pipelines with 1.17.2. I was having issues also but got it resolved.

Hope this helps! https://github.com/Azure/azure-functions-dotnet-worker/issues/2291#issuecomment-2057575535