0
votes

We are working to migrate to PackageReference restore style csproj's but have many nuspec's for such projects the rely on some of the default nuget pack CLI behavior. Specifically:

  • version substitution
  • auto-generation of dependencies section
  • auto generation of files section

Essentially, I am looking to run dotnet pack on a csproj and have it use the csproj to generate the files, dependencies and version, but an existing nuspec file for the rest of the metadata.

If I specify NuSpecFile in the csproj, it correctly uses the nuspec file, but no longer generates the files, dependencies, or version based on the csproj.

1

1 Answers

2
votes

The MSBuild based packing functionality of the .NET SDK has the option to either generate a nuspec file to use for packing (default) or use a user-supplied nuspec file (NuSpecFile property) for generating the package.

There is no functionality to mix these approaches.

I suggest putting all the metadata you need into the csproj file. See the documentation on the pack target for the list of MSBuild properties that can be used to control the package metadata.

If you are looking to share metadata across multiple projects, create a Directory.Build.props file at the root folder of your solution (directory hierarchy at or above all projects) with the contents you want to share:

<Project>
  <PropertyGroup>
    <Authors>shared authors value</Authors>
    <PackageProjectUrl>https://something</PackageProjectUrl>
    …
  </PropertyGroup>
</Project>