如何将文件复制到Azure Function bin文件夹? [英] How do you copy files into Azure Function bin folder?

查看:33
本文介绍了如何将文件复制到Azure Function bin文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我有一个Azure Function C#项目在netcoreapp3.1和Azure版本v3中运行。以下是csproj的一段代码...

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AssemblyName>someproj</AssemblyName>
    <RootNamespace>someproj</RootNamespace>
    <Product>someproduct</Product>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <RunPublishAfterBuild>true</RunPublishAfterBuild>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.15.0" />
    <PackageReference Include="Microsoft.Applications.Telemetry.Server">
      <Version>1.1.264</Version>
      <NoWarn>NU1701</NoWarn>
    </PackageReference>
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0-preview.8.20407.11">
      <NoWarn>NU1701</NoWarn>
    </PackageReference>
  </ItemGroup>
</Project>

运行后异常:

'Could not load file or assembly 'System.Configuration.ConfigurationManager, 
 Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one 
 of its dependencies. The system cannot find the file specified.'

可疑原因:

问题是,当通过Visual Studios构建azure函数时,它会创建以下文件夹结构。(请原谅我糟糕的插图)

bin/
 | - Debug/
 | | -bin / 
 | | | runtimes/
 | | - function1/
 | | | - ...
...
---
调试位于

System.Configuration.ConfigurationManager.dll/文件夹中,而不是二级bin文件夹中。当构建并查看相应的DLL文件时,我可以看到它被填充到第二个bin文件夹中,但后来在Azure Function项目启动之前被删除。

现在,当我关闭本地运行时,将System.Configuration.ConfigurationManager.dll添加回第二个bin文件夹,一切都运行得很好!

实际问题(请帮助!)

问题1:有没有办法显式地告诉Visual Studio将DLL输出到第二个bin文件夹中?我已经尝试了以下方法...

  • GeneratePathProperty=";true";
  • Copy_PASS0
  • 所有堆栈溢出
问题2:有没有更好的方法来引用这个必需的DLL?我已经尝试了Nuget主机,但没有成功。

感谢大家的帮助!

推荐答案

任务远程运行依赖项由目标运行_FunctionsBuildCleanOutput为known to purge assemblies too aggressively

解决方法是完全关闭任务(并接受更大规模的部署),方法是设置:

<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

跟踪工作项以进行更精细的切换:https://github.com/Azure/azure-functions-host/issues/5894

这篇关于如何将文件复制到Azure Function bin文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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