在最新的Azure SDK的帮助下,我获得了适用于Visual Studio的Azure Function工具 这样我就可以在本地调试我的 Azure Functions - 很酷。
我的azure函数需要使用业务对象dll的代码
从 .csx 脚本中,我可以在开头使用这样的指令来引用 .dll
#r "ServiceBusQueue.Shared.dll"
Azure 函数项目中没有“添加引用...”。 我只能添加一个Build依赖项,以便首先构建业务对象dll。
但是当更新 dll 代码时,不会将 dll 输出复制到我的 azure 函数目录的 bin 中。 发布到网络上就可以了 为了在本地调试 session 中使用最新的业务对象代码,这是必需的。
因为 Azure 函数项目中没有预构建事件选项卡,
我找到的解决方案是在 Function App 项目中编写一个 Prebuild 事件
.funproj 文件
<Target Name="BeforeBuild">
<Message Text="Copying dlls into Azure Function ..." />
<Exec Command="Call CopyDlls.cmd $(Configuration)" />
</Target>
批处理文件:
rem %1 is the configuration, debug or release
echo %1
mkdir .\ServiceBusQueueTriggerCSharp\bin
copy ..\ServiceBusQueue.Shared\bin\%1\*.* .\ServiceBusQueueTriggerCSharp\bin
rem DOS subtlety : test than return code is equal or greater than 1
rem : make the compilation to fail
if errorlevel 1 exit /b 1
这样,dll 就会被复制到 Azure Function 项目的 bin 目录中。
是否有更集成/更干净的方法来完成这样的事情?
最佳答案
不幸的是,正如您所发现的,最好的解决方法是在 funproj
中使用 MSBuild 目标。文件。
或者,您可以将构建后步骤添加到类库中。转到属性 -> 构建事件 -> 构建后事件命令行并添加类似 xcopy /Y $(TargetPath) $(SolutionDir)FunctionApp1\bin
的内容.
但是,VS 工具团队正在努力为函数工具的 future 版本添加引用功能。请参阅https://github.com/Azure/Azure-Functions/issues/90 .
关于c# - 如何添加对 Azure Function C# 项目的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41985925/