David Gard
David Gard

Reputation: 12047

Explicitly set the order of build targets defined in NuGet packages

I have a Visual Studio 2017 project for building an Azure Function App. This project contains (amongst others) two NuGet packages - Microsoft.NET.Sdk.Functions and OctoPack. The packages are referenced in this order by the .csproj file for the Project in question.

The Microsoft.NET.Sdk.Functions package contains the target _GenerateFunctionsPostBuild -

<Target Name="_GenerateFunctionsPostBuild" AfterTargets="Build">...</Target>

The OctoPack package contains the target Octopack -

<Target Name="OctoPack" Condition="$(RunOctoPack)">...</Target>

When building, it's essential that the _GenerateFunctionsPostBuild target runs before the OctoPack target, otherwise required files are not available in the NuGet package generated by OctoPack.

As I can't edit the NuGet packages directly, I'm unable to explicitly state AfterTarget="_GenerateFunctionsPostBuild" for the OctoPack target. Is there any way I can force the targets to run in the order that I require?

Upvotes: 0

Views: 584

Answers (1)

David Gard
David Gard

Reputation: 12047

In lieu of a answer, I've come up with a workaround. Instead of using OctoPack, I'm manually generating the NuGet package after the build has completed.

In the NuSpec file, I've added a couple of tokens for %Configuration% and %Version% so that I can choose the files to package based on the configuration, and obviously customise the version.

Here's what I'm doing - obviously I'm making $version before these lines.

$dir = (Get-Location).Path
& D:\nuget\4.4.1\nuget.exe pack $dir\AzureFunction\AzureFunction.nuspec -BasePath $dir\AzureFunction -Properties "Configuration=Release;Version=$version"

Upvotes: 0

Related Questions