Home: Provide MSBuild properties or items for resolved pack outputs

Created on 29 Dec 2017  路  9Comments  路  Source: NuGet/Home

When authoring custom msbuild targets that run after pack or creating custom CI scripts, it would be helpful to get the path to the resulting .nupkg(s) via msbuild properties or items.

Currently, this needs to be done by replicating what is currently done to construct a NuGetPackOutput item (which also contain .nuspec files and are used for incremental target config) through evaluating $(PackageOutputAbsolutePath)$(PackageId).$(PackageVersion).nupkg after GenerateNuspec.

To chain custom targets after Pack, properties containing this string would help and reduce duplication / reliance on implementation details. If possible, a PackageProjectOutputGroup smiler to DebugSymbolsProjectOutputGroup or DocumentationProjectOutputGroup would also help to integrate in CI scripts (but a similar target to return msbuild items could also be authored based on the previously mentioned properties)

Pack Question

All 9 comments

you should just be able to use the NuGetPackOutput item as is if you are executing a target that runs after pack. Am i missing something here?

NuGetPackOutput contains all nuspec and nupkg files (normal and symbol) so it doesn't really give semantic info about what's actually a package and what's an intermediate file used during Pack.

  <Target Name="Foo" DependsOnTargets="Pack">
    <Message Importance="high" Text="NuGetPackOutput: %(NuGetPackOutput.Identity)" />
  </Target>
  NuGetPackOutput: /Users/martin/tmp/testlib/obj/testlib.1.0.0.nuspec
  NuGetPackOutput: /Users/martin/tmp/testlib/bin/Debug/testlib.1.0.0.nupkg
  NuGetPackOutput: /Users/martin/tmp/testlib/bin/Debug/testlib.1.0.0.symbols.nupkg
  NuGetPackOutput: /Users/martin/tmp/testlib/obj/testlib.1.0.0.symbols.nuspec

I was looking for something more like @(MainAssembly) or at least some property to not "hardcode" $(PackageOutputAbsolutePath)$(PackageId).$(PackageVersion).nupkg and $(PackageOutputAbsolutePath)$(PackageId).$(PackageVersion).symbols.nupkg.

@dasMulli
can't your just filter it out based on extension?

<Target Name="Foo" DependsOnTargets="Pack">
    <Message Importance="high" Text="NuGetPackOutput: %(NuGetPackOutput.Identity)" Condition="'%(NuGetPackOutput.FileExtension)' == '.nupkg'" />
  </Target>

We have also updated the target _GetOutputItemsForPack so it will only output the symbols nupkg and nuspec if they are actually generated.

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L63-L86

I think there is enough extensibility there to figure out what you are trying to do.

Sure I can do that. It just doesn't feel "right" from a separation of concerns point of view. The new target is great. maybe if there were some metadata on the generated items to distinguish symbol packages and main packages it would also be great.

@dasMulli i would accept a PR for that, but i won't be able to give it enough priority compared to other work that needs to be done in the pack space.

Fully understand that, it absolutely isn't a high priority issue for me as well since hard-coding is always an option (and is what I've been using). I'll look into creating a PR next year.

@dasMulli one suggestion though if you continue to use the hardcoded property like you said above:
$(PackageOutputAbsolutePath)$(PackageId).$(PackageVersion).nupkg

If the PackageVersion is something like 1.0.0-alpha , it won't work, because the output filename of the nupkg has the version normalized (the file name would be PackageId.1.0.0.nupkg) . This scenario IS taken care of by the items in NuGetPackOutput, so i would suggest you use that.

I'm using custom concatenation successfully. I'm no longer sure this should be done in NuGet itself, especially if I'd be the only user..

Was this page helpful?
0 / 5 - 0 ratings