0

On Ubuntu I'd like to wrap a few C# DLL files into a NuGet package. On Windows one would use the NuGet package explorer or nuget.exe + manually edited *.csproj.nuspec. In summary when manually editing the *.nuspec file one may add DLLs via the <files> section:

<files>
   <file src="some\Path\YourDll.dll" target="lib"></file>
</files>

On Ubuntu I'd like to use dotnet pack instead. However it seems like it's not able to operate on a *.csproj.nuspec file:

Usage: dotnet pack [options] <PROJECT | SOLUTION>

Arguments:
  <PROJECT | SOLUTION>   The project or solution file to operate on. If a file is not specified, the command will search the current directory for one.

Options:
  -h, --help                            Show command line help.
  -o, --output <OUTPUT_DIR>             The output directory to place built packages in.
  --no-build                            Do not build the project before packing. Implies --no-restore.
  --include-symbols                     Include packages with symbols in addition to regular packages in output directory.
  --include-source                      Include PDBs and source files. Source files go into the 'src' folder in the resulting nuget package.
  -c, --configuration <CONFIGURATION>   The configuration to use for building the package. The default for most projects is 'Debug'.
  --version-suffix <VERSION_SUFFIX>     Set the value of the $(VersionSuffix) property to use when building the project.
  -s, --serviceable                     Set the serviceable flag in the package. See https://aka.ms/nupkgservicing for more information.
  --nologo                              Do not display the startup banner or the copyright message.
  --interactive                         Allows the command to stop and wait for user input or action (for example to complete authentication).
  --no-restore                          Do not restore the project before building.
  -v, --verbosity <LEVEL>               Set the MSBuild verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
  --runtime <RUNTIME_IDENTIFIER>        The target runtime to restore packages for.
  --no-dependencies                     Do not restore project-to-project references and only restore the specified project.
  --force                               Force all dependencies to be resolved even if the last restore was successful.
                                        This is equivalent to deleting project.assets.json.

Can I wrap C# DLLs into a NuGet package on Ubuntu using the dotnet CLI? Or do I have to use the nuget CLI (apt-get install nuget) instead with the approach like on Windows?

thinwybk
  • 4,193
  • 2
  • 40
  • 76
  • What is the `*.csproj.nuspec` file? Aren't they two different files? – Pavel Anikhouski Jan 13 '21 at 13:41
  • @PavelAnikhouski Yes, of course that are separate files. In `*.csproj.nuspec` one can define DLLs to include into a nuget package. The question is if this is possible via `*.csproj` as well. Then I could use `dotnet pack`. Otherwise I'd probably have to use `nuget` instead. – thinwybk Jan 13 '21 at 13:49
  • You can define a properties directly in `.cspoj` file, as described here [Create and publish a package (dotnet CLI)](https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli) – Pavel Anikhouski Jan 13 '21 at 13:52
  • Do you mean via ``? – thinwybk Jan 13 '21 at 13:54

1 Answers1

0

I would add this into the .csproj file:

<ItemGroup>
    <Content Include="some.dll" PackageCopyToOutput="true">
        <pack>true</pack>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

It's not pretty but it works.

zilleplus
  • 479
  • 1
  • 3
  • 12
  • I'm experimenting with ` true lib\$(TargetFramework) `. What's the difference? – thinwybk Jan 13 '21 at 15:56
  • That works? I's been a while, took this from an older project that I knew worked :-). I had quiet a bit of trouble getting it to work, providing this as example hopefully it saves you some time . – zilleplus Jan 13 '21 at 16:04
  • There are a lot of examples in github which use this. I assume it works but I don't know yet. – thinwybk Jan 13 '21 at 16:19
  • It seems like `CopyToOutputDirectory` is usually needed only if one want's to provide [static files and the like as part of the package](https://stackoverflow.com/questions/44374074/copy-files-to-output-directory-using-csproj-dotnetcore). – thinwybk Jan 13 '21 at 16:31