1

We have .Net 4.7.2 (C#) project "Common" (base project), and this is consumed by C# project "API".

API consumes Common.

I would like to add Microsoft.ML functionality to Common, and API will call into Common to exercise that functionality - but I do not want to add the ML nuget packages to API.

This should be fine as all the dll's from Common should get copied into the bin directory of API on build.....

...there are some snags though. It seems that if Common does not actually refer to any types in a referenced dll then the build process skips the copy and API does not get the dll in it's bin directory. A hack is required to work around this as detailed in an answer to:

stack overflow question - MSBuild doesn't copy references

here is my hack that causes all dependent dll's to get copied into 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());
}

...this works, except that native dll's are missed. In order to work around that I have added the dll as a file to the project and set "Copy if newer" to true.

...this is nasty! ...is there a better way?

Specifically my issue is with nuget package: "Microsoft.ML.CpuMath". Within this package is "Microsoft.ML.CpuMath.dll" and also "CpuMathNative.dll".

How to I end up with CpuMathNative.dll in Api/bin, without adding it (or any Microsoft.ML.CpuMath package) to the Api project?

This should surely be possible as surely it is quite normal to encapsulate functionality in a Common project.

tigerprawn
  • 63
  • 1
  • 8
  • 1
    What are relationships between `Common` and `API`? Are they in the same solution? – Sinatr Oct 19 '20 at 13:03
  • hello Sintra - yes they are. In our landscape there are a few similar solutions where there is a parent project dependant on "Common". We don't want to have to add unnessesary packages to any of these parents. As for the relationship - well "Common" is a project reference in "API". – tigerprawn Oct 19 '20 at 14:14
  • If projects are in different solutions, then you have to properly distribute (install) the library, means you need to package managed dll and native dlls togeter. Nuget is a solution fo such problem, you could try using it for you local projects (see [tutorial](https://www.c-sharpcorner.com/article/creating-a-local-nuget-package-repository/)), such as `Common`. Then `API` will get everything into its outputs folder. – Sinatr Oct 19 '20 at 15:21
  • @Sinatr - thanks, but projects are in the same solution and we are just trying to use the microsoft packages available to us. The point is that we should only have to add them to the Common project. – tigerprawn Oct 19 '20 at 15:36

0 Answers0