如何将在基础.net项目中使用的本机dll转换为使用项目?

时间:2020-10-19 12:39:16

标签: c# .net

我们有.Net 4.7.2(C#)项目“ Common”(基础项目),并且由C#项目“ API”使用。

API使用Common。

我想将Microsoft.ML功能添加到Common,API将调用Common来行使该功能-但我不想将ML nuget包添加到API。

这应该没问题,因为来自Common的所有dll都应复制到构建版本的API的bin目录中.....

...虽然有一些障碍。似乎,如果Common实际未引用所引用dll中的任何类型,则构建过程将跳过该副本,并且API不会在其bin目录中获取该dll。解决此问题需要黑客,具体方法如下:

stack overflow question - MSBuild doesn't copy references

这是我的黑客,导致所有相关的dll复制到bin /

// NOTE - this method present so that the build process sees some use of types
// that are in dependant libraries - this causes those libraries to get copied to the bin directory
// of any project that references Domain - e.g. Api, PP etc.
public static void Dummy()
{
    var type = typeof(Microsoft.ML.Trainers.SgdNonCalibratedTrainer);
    Console.WriteLine(type.ToString());
}

...这可行,除了遗漏了本机dll的 。 为了解决该问题,我已将dll作为文件添加到项目中,并将“如果较新则复制”设置为true。

...这太讨厌了! ...还有更好的方法吗?

特别是我的问题是与nuget包有关:“ Microsoft.ML.CpuMath”。该软件包中包含“ Microsoft.ML.CpuMath.dll”和“ CpuMathNative.dll”。

如何以Api / bin中的CpuMathNative.dll结尾而不将其(或任何Microsoft.ML.CpuMath软件包)添加到Api项目中?

这肯定应该可行,因为将功能封装在Common项目中确实很正常。

0 个答案:

没有答案
相关问题