Skip to content

Commit

Permalink
Support for PackageId in .NET Core project system
Browse files Browse the repository at this point in the history
Resolve NuGet/Home#4586.

Retrieve `PackageId` global un-evaluated property from the
`ProjectRestoreInfo` on RPS nomination. Assign the value to
`PackageSpec.Name` attribute. Use `ShortName` if the property is not
defined (current behavior).
  • Loading branch information
alpaix committed Feb 22, 2017
1 parent ffaf3ae commit c5b43d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -29,6 +29,7 @@ namespace NuGet.SolutionRestoreManager
[Export(typeof(IVsSolutionRestoreService))]
public sealed class VsSolutionRestoreService : IVsSolutionRestoreService
{
private const string PackageId = nameof(PackageId);
private const string PackageVersion = nameof(PackageVersion);
private const string Version = nameof(Version);
private const string IncludeAssets = "IncludeAssets";
Expand Down Expand Up @@ -203,7 +204,7 @@ private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRe

var packageSpec = new PackageSpec(tfis)
{
Name = projectNames.ShortName,
Name = GetPackageId(projectNames, projectRestoreInfo.TargetFrameworks),
Version = GetPackageVersion(projectRestoreInfo.TargetFrameworks),
FilePath = projectFullPath,
RestoreMetadata = new ProjectRestoreMetadata
Expand All @@ -229,6 +230,12 @@ private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRe
return packageSpec;
}

private static string GetPackageId(ProjectNames projectNames, IVsTargetFrameworks tfms)
{
var packageId = GetNonEvaluatedPropertyOrNull(tfms, PackageId, v => v);
return packageId ?? projectNames.ShortName;
}

private static NuGetVersion GetPackageVersion(IVsTargetFrameworks tfms)
{
// $(PackageVersion) property if set overrides the $(Version)
Expand Down
Expand Up @@ -331,6 +331,31 @@ public async Task NominateProjectAsync_WithDifferentPackageVersions_Fails(string
Assert.False(result, "Project restore nomination must fail.");
}

[Fact]
public async Task NominateProjectAsync_PackageId()
{
var cps = NewCpsProject("{ }");
var projectFullPath = cps.ProjectFullPath;
var pri = cps.Builder
.WithTargetFrameworkInfo(
new VsTargetFrameworkInfo(
"netcoreapp1.0",
Enumerable.Empty<IVsReferenceItem>(),
Enumerable.Empty<IVsReferenceItem>(),
new[] { new VsProjectProperty("PackageId", "TestPackage") }))
.Build();

// Act
var actualRestoreSpec = await CaptureNominateResultAsync(projectFullPath, cps.ProjectRestoreInfo);

// Assert
SpecValidationUtility.ValidateDependencySpec(actualRestoreSpec);

var actualProjectSpec = actualRestoreSpec.GetProjectSpec(projectFullPath);
Assert.NotNull(actualProjectSpec);
Assert.Equal("TestPackage", actualProjectSpec.Name);
}

private async Task<DependencyGraphSpec> CaptureNominateResultAsync(
string projectFullPath, IVsProjectRestoreInfo pri)
{
Expand Down

0 comments on commit c5b43d2

Please sign in to comment.