Skip to content

Commit

Permalink
Simplify package feed queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Qonfused committed May 29, 2024
1 parent 2739fb8 commit 3f41a38
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<RemoveDir Directories="@(FoldersToClean)" />
</Target>

<Target Name="GetSDKPackagePaths"
BeforeTargets="UpdateFeed">
<Target Name="UpdateFeed"
AfterTargets="Pack">
<!-- Query all existing package versions in the feed -->
<ItemGroup>
<_SDKPackagePaths Include="$(FeedOutputPath)\**\*.nupkg" />
<_SDKPackagePaths>
Expand All @@ -25,20 +26,25 @@
<Version>$([System.IO.Path]::GetFileName('%(VersionPath)'))</Version>
</_SDKPackagePaths>
</ItemGroup>
</Target>

<Target Name="UpdateFeed"
AfterTargets="Pack">
<!-- Clean the local feed -->
<!-- Clean the local feed of old package versions -->
<PropertyGroup>
<FeedPackagePath>$(FeedOutputPath)\$(MSBuildProjectName.ToLower())</FeedPackagePath>
<SDKPackageVersion>%(_SDKPackagePaths.Version)</SDKPackageVersion>
</PropertyGroup>
<RemoveDir Directories="@(_SDKPackagePaths->'$(FeedOutputPath)\%(VersionPath)');
@(_SDKPackagePaths->'$(NuGetPackageRoot)\%(VersionPath)')"
Condition="Exists($(FeedPackagePath))" />
<!-- Add the built packages to the local feed -->
<Exec Command="$(NuGetExePath) init $(PackageOutputPath) $(FeedOutputPath)" />

<!-- Add the built package to the local feed -->
<ItemGroup>
<_SDKPackageSources Include="$(PackageOutputPath)\$(MSBuildProjectName).*.nupkg" />
</ItemGroup>
<PropertyGroup>
<SDKPackageVersion>%(_SDKPackagePaths.Version)</SDKPackageVersion>
<PackagePath>$(PackageOutputPath)\$(MSBuildProjectName).$(SDKPackageVersion).nupkg</PackagePath>
<PackagePath Condition="!Exists($(PackagePath))">%(_SDKPackageSources.Identity)</PackagePath>
</PropertyGroup>
<Exec Command="$(NuGetExePath) add $(PackagePath) -Source $(FeedOutputPath)" />
</Target>

</Project>

0 comments on commit 3f41a38

Please sign in to comment.