Build Error with pre-compiled Azure Function Libra

2019-02-23 09:23发布

问题:

Recently, I converted an Azure Function that used a C# script (*.csx) to a pre-complied class library using the Visual Studio Studio Tools for Azure Functions. It builds successfully in Visual Studio 2017 (as well as running and debugging too).

I'd like to build this AF library via our CI process. However, when I run the command dotnet build locally it fails with the following error:

C:\Users\ray\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Microsoft.Azure.WebJobs.Host, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

The same error also occurs in our CI build.

Not sure why this error is occurring and how to resolve it. Is it the version of the dotnet CLI (I'm using v1.1)? Is it something else?

回答1:

UPDATE 2018-01-08

According to a new answer by @theGRS https://stackoverflow.com/a/48156446/621827 this has been resolved.

Previous Answer

Here's what I've found.

dotnet msbuild uses the Microsoft.NET.Sdk.Functions .NETStandard 1.5 library which if you look at the dependencies on NuGet it doesn't use Microsoft.Azure.WebJobs

But if you use the Visual Studio 2017 msbuild it will use the .NETFramework 4.6 version of the library which includes Microsoft.Azure.WebJobs.

My suggestion is to use MSBuild for now. I've written a tutorial on how to do this.



回答2:

I was having the same issue as well when running dotnet build, but no longer have this issue after updating Microsoft.NET.Sdk.Functions from 1.0.2 to 1.0.7.

Update to the latest version of this package in your Nuget package manaager and you should be able to run dotnet build again.