如何添加对Azure Function C#项目的引用?

Emm*_*RIN 4 c# msbuild csproj azure azure-functions

在最新的Azure SDK的帮助下,我获得了针对Visual Studio的Azure功能工具,以便我可以在内部调试我的Azure功能 - 很酷.

我的azure函数需要使用Business对象的代码

从.csx脚本开始,我可以使用这样的指令引用.dll

#r  "ServiceBusQueue.Shared.dll"
Run Code Online (Sandbox Code Playgroud)

Azure功能项目中没有"添加引用...".我只能添加一个Build依赖项,以便首先构建业务对象dll.

但是当更新DLL代码时,不会将dll输出复制到我的azure函数目录的bin中.在Web上发布是正确的这是为了在本地调试会话中使用最新的业务对象代码.

因为Azure功能项目中没有Prebuild事件的选项卡,所以我找到的解决方案是Prebuild event在Function App项目中编写一个

.funproj文件

<Target Name="BeforeBuild">
    <Message Text="Copying dlls into Azure Function ..." />
    <Exec Command="Call CopyDlls.cmd $(Configuration)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

批处理文件:

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
Run Code Online (Sandbox Code Playgroud)

这样,dll就会复制到Azure Function项目的bin目录中.

是否有更综合/更清洁的方式来做这样的事情?

Mat*_*son 7

不幸的是,正如您所发现的,最好的解决方法是在funproj文件中使用MSBuild目标.

或者,您可以向类库添加构建后步骤.转到属性 - >构建事件 - >构建后事件命令行并添加类似的内容xcopy /Y $(TargetPath) $(SolutionDir)FunctionApp1\bin.

但是,VS工具团队正在为函数工具的未来版本添加参考功能.请参阅https://github.com/Azure/Azure-Functions/issues/90.