问题描述
背景:
我有一个运行在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
- 所有stackoverflows
问题2:是否有更好的方法来引用此必需的dll?我已经尝试过nuget控制台,但是没有运气。
谢谢大家的帮助!
解决方法
由Target _FunctionsBuildCleanOutput运行的任务RemoveRuntimeDependencies是known to purge assemblies too aggressively。
解决方法是通过设置以下操作完全关闭任务(并接受更大的部署):
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
跟踪工作项以进行更精细的切换:https://github.com/Azure/azure-functions-host/issues/5894