背景:
我有一个基于netcoreapp3.1和Azure v3版本的Azure函数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 项目启动之前立即被删除。
现在,当我关闭本地运行,并将 System.Configuration.ConfigurationManager.dll 添加回二级 bin 文件夹中时,一切都工作得非常完美!
实际问题(请帮忙!)
问题1:有没有一种方法可以明确告诉 Visual Studio 将 dll 输出到二级 bin 文件夹中?我已经尝试过以下操作...
- GeneratePathProperty="true"
- COPY_PASS0
- 所有的 stackoverflow 问题
问题2:有更好的方法引用这个必需的 dll 吗?我已经尝试过 nuget 控制台,但没有成功。
感谢您的协助!