【发布时间】:2021-01-04 22:44:13
【问题描述】:
背景:
我有一个在 netcoreapp3.1 和 azure 版本 v3 中运行的 Azure Function C# 项目。这是csproj的sn-p...
<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 控制台,但没有运气。
感谢大家的帮助!
【问题讨论】:
标签: c# asp.net-core azure-functions system.configuration netcoreapp3.1