Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cleanest way to package content files in .nuget package

So I have set up which looks something like following:

Source.sln have three project A.csproj, B.csproj and utils.csproj. Both A and B use utils.csproj but I have converted utils.csproj to a nuget package so now A and B both consume utils nuget package instead of a project reference.

next thing I do is make nuget packakage from both bot A and B. So now I have three nuget packages

1.A.Nuget(uses utils.nuget) 2.B.nuget(uses utils.nuget) 3. Utils.nuget

Now, I have another consumer.csproj which uses all three as nuget references.

The problem here is that Both A.csproj and B.csproj had inputA.json and inputB.json files which are required at the runtime. They do not change at all so it is better that they are packaged with nuget package

My question is that what is the cleanest way to paclage them? I thought of couple of options but am not satisfied by either of them:

  1. pack them in utils.nuget's /content folder by specifying that in .csproj file. But the problem here is that the code reading them from nuget needs to reference thse files from ../contents/inputA.json which is not the case in Development environment. They simply reside in A.csproj/ folder and can be referenced as "input.json". So the same code which works on Visual studio(referencing this file as input.json) would break when consumer.csproj references A.nuget and utils.nuget

    1. have Consumer supply all these files. This could be an option but I want to avoid it if possible.

    2. Somehow figure out a way to copy this files into /lib folder of utils.nuget instead of /contents. I am currently trying to achieve this using .nuspec file. but not sure if this is the cleanest solution

Can I do something better about this situation?

like image 465
Lost Avatar asked Oct 17 '25 11:10

Lost


1 Answers

The cleanest(which is inherently not a very clean) to pack files and read it from everywhere is to basically make sure that these files end up in consumer project's /bin folder. The way to do this is using .nuspec file.

If files are mapped inside .nuspec metadata as .nuspec file:

<metadata> // This path automatically resolves to /contentfiles/any/any <contentFiles> <files include="Yourfilename" buildAction="none" copyToOutput="true"/> </contentFiles> </metadata>

<files> <file src="../path/to/your/file" target="contentFiles\any\any" />
</files>

because of the option CopyToOutput = "true" These files would directly be copied to /bin folder of referencing project.

like image 62
Lost Avatar answered Oct 20 '25 01:10

Lost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!