如何添加对Azure Function C#项目的引用? [英] How to add a reference to an Azure Function C# project?

查看:86
本文介绍了如何添加对Azure Function C#项目的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助最新的Azure SDK,我获得了适用于Visual Studio的Azure功能工具 这样我就可以在本地调试Azure功能了.

With the help of the latest Azure SDK, I got the Azure Function tools For Visual Studio So that I can debug my Azure Function on premises - cool.

我的azure函数需要使用业务对象dll的代码

My azure function needs to use the code of a Business object dll

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

From the .csx script I can make a reference to the .dll with such a directive at the start

#r  "ServiceBusQueue.Shared.dll"

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

There is no "Add reference..." in an Azure function project. I can only add a Build dependency so that the business object dll is built first.

但是更新dll代码时,没有将dll输出复制到我的azure函数目录的bin中. 可以在网络上发布 为了使最新的业务对象代码在本地调试会话中使用,这是必需的.

But when the dll code is updated there is no copying of the dll output to the bin of my azure function directory. Publish on the web is ok This is required in order for the latest business object code to be used in local debug session.

由于Azure功能项目中没有用于预生成事件的选项卡, 我发现的解决方案是在Function App项目中编写Prebuild event

Because there is no tab for Prebuild events in an Azure function project, the solution I have found is to write a Prebuild event in the Function App project

.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目录中.

That way the dll is copied in the bin directory of the Azure Function project.

有没有更集成/更清洁的方法来做这种事情?

Is there a more integrated/cleaner way to do such a thing ?

推荐答案

不幸的是,最好的解决方法是,在funproj文件中使用MSBuild目标.

Unfortunately the best workaround for this is, as you've discovered, to use a MSBuild target in the funproj file.

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

Alternatively, you can add a post-build step to your class library. Go to Properties -> Build Events -> Post-build event command line and add something like xcopy /Y $(TargetPath) $(SolutionDir)FunctionApp1\bin.

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

However, the VS tooling team is working on adding reference functionality for a future release of the functions tooling. See https://github.com/Azure/Azure-Functions/issues/90.

这篇关于如何添加对Azure Function C#项目的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆