我有一个打包到nuget包中的netstandard 2.0库,将其称为A。我引用了该库中的另一个包,将其称为B。
编辑(更多信息):程序包B依赖于其他nuget程序包,这些程序包是通过SWIG移植的c ++代码。当我在程序包B中引用这些程序包时,.dll,.dylib和.so文件与程序包B的源代码一起安装。当我的netcore应用程序中发生运行时错误时,这些文件“找不到” “
然后,我编写一个引用包A的netcore应用。但是,当我尝试执行该应用时,出现运行时错误,提示它找不到包B的方法。因此,我必须直接引用nuget包B。在netcore .csproj文件中。我没有从netcore应用直接调用程序包B中的代码。它们是通过程序包A抽象的方法调用,程序包A依赖于程序包B中的代码。
我的问题很简单,如何更改.csproj文件,这样就不必在netcore .csproj文件中显式引用程序包B?就像我的标题所暗示的那样,我如何“打包”软件包B,这样就不必在我的网络核心应用中再次引用它了?
.csproj文件示例,以便清楚:
netstandard库
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>My library A</Title>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="B" Version="1.0.0" />
<PackageReference Include="some_c++_SWIG" Version="1.0.0" />
</ItemGroup>
</Project>
netcore应用
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>My netcore app</Title>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="A" Version="1.0.0" />
<!-- Why do I have to include B and SWIG pkg again??? -->
<PackageReference Include="B" Version="1.0.0" />
<PackageReference Include="some_c++_SWIG" Version="1.0.0" />
</ItemGroup>
</Project>
project.assets.json
".NETCoreApp,Version=v2.1": {
"B/1.0.0": {
"type": "package",
"dependencies": {
"another_package": "1.0.0"
},
"compile": {
"lib/netstandard2.0/B.dll": {}
},
"runtime": {
"lib/netstandard2.0/B.dll": {}
}
},
...
"libraries": {
"B/1.0.0": {
"sha512": "abc123",
"type": "package",
"path": "B/1.0.0",
"files": [
".nupkg.metadata",
"B.1.0.0.nupkg.sha512",
"B.nuspec",
"lib/netstandard2.0/B.dll"
]
},
...
"frameworks": {
"netcoreapp2.1": {
"dependencies": {
"B": {
"target": "Package",
"version": "[1.0.0, )"
},
这是示例错误消息: (其中c_csharp_metrics具有在软件包B中安装/引用的.dll,.dylib和.so文件)
Encountered exception: System.TypeInitializationException: The type initializer for 'c_csharp_metricsPINVOKE' threw an exception. --->
System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. --->
System.DllNotFoundException: Unable to load shared library 'c_csharp_metrics’ or one of its dependencies.
In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable:
libc_csharp_metrics: cannot open shared object file: No such file or directory
at c_csharp_metricsPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_c_csharp_metrics(ExceptionDelegate applicationDelegate,
ExceptionDelegate arithmeticDelegate,
ExceptionDelegate divideByZeroDelegate,
ExceptionDelegate indexOutOfRangeDelegate,
ExceptionDelegate invalidCastDelegate,
ExceptionDelegate invalidOperationDelegate,
ExceptionDelegate ioDelegate,
ExceptionDelegate nullReferenceDelegate,
ExceptionDelegate outOfMemoryDelegate,
ExceptionDelegate overflowDelegate,
ExceptionDelegate systemExceptionDelegate)
at c_csharp_metricsPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at c_csharp_metricsPINVOKE.SWIGExceptionHelper..ctor()
at c_csharp_metricsPINVOKE..cctor()
--- End of inner exception stack trace ---
at c_csharp_metricsPINVOKE.new_metrics__SWIG_0()
at metrics..ctor()