title: Packing and publishing NuGet packages with .NET CLI in TeamCity
body: <p>I am trying to create Team City build template which requires minimum customisation, and I want it to play nicely with legacy projects and projects developed with .NET Core/Standard and .NET CLI.
  I am stuck with NuGet as there were some considerable changes in how things work. </p>
  
  <p>Earlier we had to create <code>nuspec</code> file to pack project as a NuGet package. At least in that file we could define various package-related properties.</p>
  
  <p>New <code>csproj</code> file format allows us to define all package properties inside itself. That's fine, but how then do we know which projects should be packaged and which should not?</p>
  
  <p>So far our TeamCity's build step <code>Pack NuGet</code> just contained <code>**.nuspec</code> for <code>Specification files:</code> field. The very fact of <code>nuspec</code> file presence served like a flag <code>pack &amp; publish this project</code>.</p>
  
  <p>However, for <code>dotnet pack</code> we need to specify the project. There is no simple way to distinguish 'main' projects from 'auxiliary' ones on which mains depend. (Let us ignore that project-to-project references are currently not supported.)</p>
  
  <p>We either could pack all projects specifying <code>**.*proj</code> (yet in that case we are to know which packages to publish) or we might specify projects explicitly in a build configuration, but I don't like this approach because you must edit build configuration each time new project is added to the solution.</p>
  
  <p>I also considered the option <code>Generate package on build</code> and omit <code>dot net pack</code> step as package is created on build. The only thing left is publishing the packages with <code>dotnet nuget push</code> specifying  <code>**/%BuildConfiguration%/*.nupkg</code>.
  Unfortunately when starting build against solution without projects with enabled <code>Generate package on build</code> makes TC fail complaining that</p>
  
  <blockquote>
    <p>Target files not found for pattern "**/Release/*.nupkg"</p>
  </blockquote>
  
  <p>Hence, I either need another recipe for achieving the required result or an advice how to make TC consider empty result just as a NOP and mark build as successful.</p>
  
  <p>Yet another option is to use <code>nuspec</code> even for new <code>csproj</code>...  </p>