8
votes

I'd like to create a nuget package (from some c# project), but I don't want to embed the generated dll, but just some static files instead.

I added a tag at the end of my nuspec file, but nuget pack command continues to embed the project.dll in the package. The thing is I don't want this dll to be published.

Is there any way to do that?

Thanks,

RĂ©gis

3

3 Answers

5
votes

Yes. You can create a .nuspec file that simply references the content files.

You must use nuget pack MyPackage.nuspec

Don't pack the .csproj file as that causes NuGet to include the built assembly.

See http://docs.nuget.org/create/nuspec reference for more info.

4
votes

To package a file as content, you must use target=content when listing the file in your .nuspec document.

To create a 'content only' nuget package, you must use a <files> node to list the files.

A <files> node must be a sibling of the <metadata> node.

A <file> node must be a child of a <files> node.

To include a file as content, set the target attribute in a <file> node to 'content'.

Example:

  <files>
    <file src="{filePath}" target="content"/>
  </files>

As previously mentioned, you must then pack the .nuspec file rather than a .csproj file:

nuget pack *.nuspec

I found the target=content trick here:

https://docs.microsoft.com/en-us/nuget/reference/nuspec#including-content-files

1
votes

For contentFiles i use this way in the nuspec file :

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>    
    <id>DummyNuget</id>
    <version>1.0.1-alpha</version>
    <title>DummyNuget</title>
    <authors>DummyNuget</authors>
    <owners>DummyNuget</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>DummyNuget</description>
    <releaseNotes></releaseNotes>
    <copyright>2019</copyright>
    <tags></tags>
    <contentFiles>
        <files include="**\*.*" buildAction="Content" copyToOutput="true" />
    </contentFiles>
  </metadata>
  <files>
    <file src="<path to files>\*.*" target="contentFiles\any\any" />    
  </files>
</package>

files to put the local files in the nuget package then contentFiles in the metadata to put all the files in the project as content copy to output