natemcmaster
natemcmaster

Reputation: 26773

How to exclude assembly from NuGet package when packing csproj?

I want to use "dotnet pack" to produce a nuget package, but I don't want to include the assembly file. My project doesn't have code, yet calling "dotnet pack" creates a package with an empty assembly in it.

How can I do this using csproj and dotnet.exe?

Upvotes: 15

Views: 9334

Answers (1)

natemcmaster
natemcmaster

Reputation: 26773

You have two options:

  1. Use a nuspec file instead of csproj. NuGet's support for packs a csproj is not as flexible as using the nuspec directly. See https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-nuspec-package-manifest-file
  2. In your csproj file, set the property <IncludeBuildOutput>false</IncludeBuildOutput> (add to a PropertyGroup section). This instructs the "Pack" target not to add the assembly to the package. See https://learn.microsoft.com/en-us/nuget/schema/msbuild-targets for more details.

Upvotes: 23

Related Questions