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

标签 c# azure msbuild csproj azure-functions

在最新的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/

相关文章:

c# - 在 C# 中一次通过 X 线程的操作列表进行线程化

python - 无法使用python从Azure Key Vault获取 secret /证书| 'KeyVaultManagementClient' 对象没有属性 'get_secret'

c# - 构建后事件在使用 Wix Sharp 在 Visual Studio 中构建 MSI 之前执行

visual-studio - MSBuild 在 VS2010/2013 成功的地方失败 - 混合 3.5 和 4.0 - 为什么?

c# - 如何断言控制台的结果与预期相同?

C# async/await 进度报告不符合预期顺序

azure - 记住 Azure Active Directory Xamarin Forms 中上次登录的用户

msbuild - 如果目标失败,则停止 msbuild 进程

c# - 如何将 xml 绑定(bind)到 wpf TreeView ?

azure - 从 Azure Application Insights 删除/清除数据