如何将文件复制到 Azure Function bin 文件夹中?

2024-01-26

背景:

我有一个在 netcoreapp3.1 和 azure 版本 v3 中运行的 Azure Function C# 项目。这是 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/
 | | | - ...
...
---

系统.配置.ConfigurationManager.dll位于 Debug/ 文件夹中,而不是第二级 bin 文件夹中。当构建并查看相应的 dll 文件时,我可以看到它填充在第二个 bin 文件夹中,但随后在 Azure Function Projects 启动之前被删除。

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

实际问题(请帮忙!)

问题1:有没有办法明确告诉Visual Studio将dll输出到第二个bin文件夹中?我已经尝试过以下...

  • 生成路径属性=“真”
  • 复制_PASS0
  • 所有堆栈溢出

问题2:有没有更好的方法来引用这个所需的dll?我已经尝试过 nuget 控制台,但没有成功。

谢谢大家的帮助!


由 Target _FunctionsBuildCleanOutput 运行的任务 RemoveRuntimeDependency 是众所周知,清洗组件过于积极 https://github.com/Azure/Azure-Functions/issues/1518.

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

<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将文件复制到 Azure Function bin 文件夹中? 的相关文章

随机推荐