Skip to content

Commit 23e5c78

Browse files
committed
Resolve wildcard dependency just like central package versions
When dependency has a wildcard, we can use the exact same approach we use to resolve empty version in centrally managed package versions. Fixes #64
1 parent e673d6a commit 23e5c78

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/NuGetizer.Tasks/NuGetizer.Inference.targets

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Copyright (c) .NET Foundation. All rights reserved.
432432
<Target Name="_UpdatePackageReferenceVersions"
433433
Inputs="@(PackageReference)"
434434
Outputs="|%(Identity)|"
435-
Condition="'$(UsingMicrosoftNETSdk)' == 'true' and '$(ManagePackageVersionsCentrally)' == 'true'"
435+
Condition="'$(UsingMicrosoftNETSdk)' == 'true'"
436436
DependsOnTargets="RunResolvePackageDependencies"
437437
Returns="@(_CentrallyManagedDependency)">
438438

@@ -442,19 +442,20 @@ Copyright (c) .NET Foundation. All rights reserved.
442442
<_CandidatePackageIsImplicit>%(PackageReference.IsImplicitlyDefined)</_CandidatePackageIsImplicit>
443443
</PropertyGroup>
444444

445-
<ItemGroup Condition="'$(_CandidatePackageVersion)' == '' and '$(_CandidatePackageIsImplicit)' != 'true'">
446-
<_CentrallyManagedDependency Include="@(PackageDependencies)"
447-
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('$(_CandidatePackageId)/')) and
448-
$([MSBuild]::ValueOrDefault('%(ParentPackage)', '')) == ''" />
445+
<ItemGroup Condition="$(_CandidatePackageIsImplicit) != 'true' and
446+
($(_CandidatePackageVersion) == '' or $(_CandidatePackageVersion.Contains('*')))">
447+
<_ResolvedPackageDependency Include="@(PackageDependencies)"
448+
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('$(_CandidatePackageId)/')) and
449+
$([MSBuild]::ValueOrDefault('%(ParentPackage)', '')) == ''" />
449450
</ItemGroup>
450451

451-
<PropertyGroup Condition="'@(_CentrallyManagedDependency)' != ''">
452-
<_CentrallyManagedDependency>%(_CentrallyManagedDependency.Identity)</_CentrallyManagedDependency>
453-
<_CentrallyManagedVersion>$(_CentrallyManagedDependency.Replace('$(_CandidatePackageId)/', ''))</_CentrallyManagedVersion>
452+
<PropertyGroup Condition="'@(_ResolvedPackageDependency)' != ''">
453+
<_ResolvedPackageDependency>%(_ResolvedPackageDependency.Identity)</_ResolvedPackageDependency>
454+
<_ResolvedPackageVersion>$(_ResolvedPackageDependency.Replace('$(_CandidatePackageId)/', ''))</_ResolvedPackageVersion>
454455
</PropertyGroup>
455456

456-
<ItemGroup Condition="'$(_CentrallyManagedVersion)' != ''">
457-
<PackageReference Update="@(PackageReference)" Version="$(_CentrallyManagedVersion)" />
457+
<ItemGroup Condition="'$(_ResolvedPackageVersion)' != ''">
458+
<PackageReference Update="@(PackageReference)" Version="$(_ResolvedPackageVersion)" />
458459
</ItemGroup>
459460

460461
</Target>

src/NuGetizer.Tests/given_packinference.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,5 +628,32 @@ public void when_packing_dependencies_then_includes_satellite_resources_for_priv
628628
}));
629629
}
630630

631+
[Fact]
632+
public void when_packing_dependencies_then_resolves_wildcard()
633+
{
634+
var result = Builder.BuildProject(
635+
"""
636+
<Project Sdk="Microsoft.NET.Sdk">
637+
<PropertyGroup>
638+
<OutputType>Exe</OutputType>
639+
<TargetFramework>netstandard2.0</TargetFramework>
640+
<IsPackable>true</IsPackable>
641+
<LangVersion>Latest</LangVersion>
642+
</PropertyGroup>
643+
644+
<ItemGroup>
645+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.*" />
646+
</ItemGroup>
647+
</Project>
648+
""", output: output);
649+
650+
result.AssertSuccess(output);
651+
652+
Assert.DoesNotContain(result.Items, item => item.Matches(new
653+
{
654+
PackFolder = "Dependency",
655+
Version = "4.0.*",
656+
}));
657+
}
631658
}
632659
}

0 commit comments

Comments
 (0)