4

I am creating a project (backend) which is distributed as a NuGet package. The package should add files (js, css, vue, json,...) to the consuming project on installation. This is necessary because the consuming project should be able to work with the files directly.

Both projects are .NET Core (.csproj).

I tried the following:

  1. Add files via content and contentFiles to the package.
  2. Add an init.ps1 and install.ps1 file to the tools folder in the package.

None of the above works.

What's the preferred way to add these files to the project? Is it even possible by installing a NuGet package?

I have seen that it works in the Umbraco CMS via install.ps1 but that's .NET Framework.


Edit: I have tried it now with a *.targets file.

This is the NuGet package content:

enter image description here (Inspired by the RavenDB.Embedded package)

Problem here is this will only link to the files in the project but not actually copy them to the project on disk.

The generated .nuspec file contains the following items:

    <contentFiles>
      <files include="any/any/Resources/Countries/countries.de-de.json" buildAction="None" copyToOutput="true" />
      <files include="any/any/Resources/Countries/countries.en-us.json" buildAction="None" copyToOutput="true" />
      <files include="any/any/Resources/Localization/zero.en-us.json" buildAction="None" copyToOutput="true" />
    </contentFiles>

Consuming solution:

enter image description here


Edit 2: I want to reach this goal:

(Taken from here where install.ps1 was used)

enter image description here

tobi.at
  • 1,267
  • 13
  • 18
  • What do you mean by "should add files"? Should they be copied to output folder on build or added to the solution as source files? – thatguy Aug 05 '20 at 09:49
  • @thatguy they should be added to the solution as content files on package installation. – tobi.at Aug 05 '20 at 10:07
  • That is possible with `contentFiles`. Do you mind showing your attempt, so we can identify what might be going wrong? – thatguy Aug 05 '20 at 10:22
  • @thatguy Thanks. I have included an update in the description. As you can see files are added to the project now, but only linked and not copied. – tobi.at Aug 05 '20 at 10:40
  • The behavior of `contentFiles` is to be added as link to the corresponding project and optionally being copied to the output directory. They are *immutable* by definition. Apart from that, you are able to work with them. If the problem is that they cannot be *modified*, `contentFiles` cannot do that. – thatguy Aug 05 '20 at 10:51
  • @thatguy And which command or whatever can copy my files into the project on package installation if not `contentFiles`? Can I solve this issue with the `.targets` file? – tobi.at Aug 05 '20 at 10:56
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/219268/discussion-between-thatguy-and-tobi-at). – thatguy Aug 05 '20 at 12:57
  • 3
    @tobi.at Did you get this question answered via chat? – C. Augusto Proiete Aug 17 '20 at 18:47
  • @C.AugustoProiete sadly not, no. – tobi.at Aug 18 '20 at 09:48
  • 1
    Did you figure this out in the meantime? I have a similar case, where I want to package up a .NET (Core/6) project into NuGet, but one that also includes JS files (for Gulp) that should be possible to reference from the consuming project's Node modules (and also a package.json for NPM): https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/issues/23#issuecomment-1030951912 – Piedone Feb 10 '22 at 18:00
  • 1
    I have the same problem. I want to copy the file to project only during installation. – Volodymyr Liashenko Apr 18 '22 at 03:37
  • @VolodymyrLiashenko I've the same problem and try to copy XSD-Files. I also want to copy the exact same file from nuget to multiple different locations of that project. Are there any solutions to that problem? – Sebastian Schumann May 04 '23 at 12:23

0 Answers0