[英]How do you include a pinvoked dll in a NuGet package?
我正在制作这个 NuGet包( 源代码 ),它包含了一个dll libxgboost.dll
(它是从XGBoost构建的 )。 但是,它目前正在抛出异常,因为它找不到libxgboost.dll
。
如何将libxgboost.dll
包含到我的NuGet包中,以便我可以将其libxgboost.dll
?
调用代码(安装包)
using System;
using XGBoost;
namespace TestXGBoostPackage
{
class Program
{
static void Main(string[] args)
{
XGBRegressor r = new XGBRegressor();
float[][] X = new float[2][];
X[0] = new float[2];
X[0][0] = 0;
X[1] = new float[2];
X[1][0] = 1;
float[] y = {0, 1};
r.Fit(X, y);
Console.ReadKey();
}
}
}
调用Fit()引发异常
An unhandled exception of type 'System.DllNotFoundException' occurred in XGBoost.dll
Additional information: Unable to load DLL 'libxgboost.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
函数PInvoked的DLL导入语句由Fit()
[DllImport("libxgboost.dll")]
public static extern int XGDMatrixCreateFromMat(float[] data, ulong nrow, ulong ncol,
float missing, out IntPtr handle);
包的nuspec文件
<?xml version="1.0"?>
<package >
<metadata>
<id>PicNet.XGBoost</id>
<version>0.0.2.1</version>
<title>XGBoost.Net</title>
<authors>John Smith</authors>
<owners>John Smith</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>https://github.com/PicNet/XGBoost.Net</projectUrl>
<iconUrl>http://www.picnet.com.au/wp-content/uploads/2015/01/logo-dark.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>.Net wrapper for the XGBoost machine learning library.</description>
<releaseNotes>test dll dependency fix</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>machine learning xgboost boosted tree</tags>
</metadata>
</package>
在包的项目属性中,构建输出路径是bin\\Debug\\
,平台目标是x64
。
您可以为本机库打包一个本机NuGet包,
https://docs.nuget.org/ndocs/create-packages/native-packages
然后您的托管NuGet包可以依赖于此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.