How to fix error when publishing Azure function with Project reference?

NuuuFt 20 Reputation points
2024-11-20T12:36:42.32+00:00

I’ve created an Azure Function with a Timer Trigger that works fine and can be deployed successfully. However, after adding a project reference from the Azure Function to another project in the same solution, I can no longer deploy the Azure Function.

Error Details:
Metadata file 'C:\Users\x\source\repos\Sol\projectName\obj\Release\net8.0\win-x64\ref\xx.dll' could not be found.

The xx.dll file isn’t present in the win-x64\ref folder, though it does exist in C:\Users\x\source\repos\Sol\projectName\obj\Release\net8.0\ref.

Steps I’ve Tried:

  1. Cleaning the solution.
  2. Rebuilding the solution.
  3. Deleting the bin and obj folders for both the Azure Function project and the referenced project, followed by rebuilding.

Despite these steps, the problem persists. As soon as I add the project reference, publishing the Azure Function fails.

Has anyone encountered this issue before or knows how to resolve it? Any help would be greatly appreciated!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,214 questions
{count} votes

Accepted answer
  1. Ryan Hill 29,296 Reputation points Microsoft Employee
    2024-11-22T15:57:45.8433333+00:00

    Glad to hear you were able to resolve your issue @NuuuFt. I will say, it's not customary to reference a web app project in that manner. So, by creating a new library with your logic that can be shared by both the function app and the web app is the right way to go.

    However, if these two projects live under the same solution, then using a project reference directly should have still worked. If you referenced the ProjectName.dll by path, then you would need to make sure that binary was set to Copy to output folder via the Properties Visual Studio. Based on your error message, this wasn't done, and the runtime was looking for the dll in a folder that doesn't exist on the Azure Functions platform.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. NuuuFt 20 Reputation points
    2024-11-22T12:00:26.26+00:00

    Resolved by using a shared library instead of referencing the project directly.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.