4

背景:

我有一个在 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/
 | | | - ...
...
---

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

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

实际问题(请帮助!)

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

  • GeneratePathProperty="true"
  • COPY_PASS0
  • 所有的堆栈溢出

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

谢谢大家的帮助!

4

1 回答 1

6

Task, RemoveRuntimeDependencies, run by Target, _FunctionsBuildCleanOutput, is known to purge assemblies too aggressively.

The workaround is to turn off the task entirely (and accept larger deployments) by setting:

<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

Tracking work item for more granular toggles: https://github.com/Azure/azure-functions-host/issues/5894

于 2020-09-18T10:36:52.157 回答