0

We are looking to use Nuget to share code between repos.

I have created a Nuget package which contains all of the source code in a specified sub directory. In 7Zip I can explore it and see all of the files are present.

I need to import it into another project, maintaining the directory structure so the project can build, be debugged etc.

So I have:

../repo/applications/CommonCore

But CommonCore comes from the imported nuget package.

When I import this Nuget package no files seem to be present and there is no obvious way of controlling which directory it would go to.

I have read about using the contentFiles tag to specify all of the source files but this is infeasible for me as there are hundreds of files in various subdirectories so I attempted to use a format like:

<contentFiles>
    <files include="Fabric\*.*" buildAction="Content" copyToOutput="true" />
</contentFiles>

and

<files>
    <file src="*.*" target="contentFiles\Fabric" />  
</files>

But this has not helped.

Am I misunderstanding how Nuget works? Or have I just implemented it incorrectly?

Stefan
  • 3,669
  • 2
  • 32
  • 43

1 Answers1

0

NuGet packages are designed for binary dependencies, so the normal thing to do here is build the code from one repo, publish the resulting binaries (not the source code) in a NuGet package, then reference that package from your other project.

You can include whatever you like in a NuGet package so it is possible to add source files, but trying to use them as a way of doing source dependencies isn't what they're designed for.

rbennett485
  • 1,907
  • 15
  • 24
  • I know that they were not originally designed for it but from looking at the docs it looks like they can do it – Stefan Jul 20 '21 at 16:03
  • @Stefan you asked if you are misunderstanding how NuGet works, and if you are trying to use it for source dependencies then the answer is yes, you are misunderstanding how it works. Your use case isn't unusual, it's exactly the use case NuGet is designed for – rbennett485 Jul 20 '21 at 23:08
  • Sorry, if my case is exactly the use case nuget is designed for how am I misunderstanding how it works? I now have the files included but I need them to go to a specific directory and they always seem to go to the package directory despite various answers saying you can alter the target directory. – Stefan Jul 21 '21 at 07:31
  • @Stefan I mean your use case of sharing code between repositories. And the way to achieve it is to build the code from one repository, publish the resulting binaries in a NuGet package, and consume that package via `PackageReference` in the other repository (not by trying to put the source code itself into the NuGet package) – rbennett485 Jul 21 '21 at 12:48