Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
ReadOnly="true"
Visible="false" />

<!-- Include declaration locations in the restore snapshot so source-only edits also trigger nomination. -->
<StringProperty Name="DefiningProjectColumnNumber"
ReadOnly="true"
Visible="false" />

<StringProperty Name="DefiningProjectFullPath"
ReadOnly="true"
Visible="false" />

<StringProperty Name="DefiningProjectLineNumber"
ReadOnly="true"
Visible="false" />

<StringProperty Name="ExcludeAssets"
ReadOnly="true"
Visible="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.VisualStudio.IO;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Text;

namespace Microsoft.VisualStudio.ProjectSystem.PackageRestore;
Expand Down Expand Up @@ -81,6 +82,34 @@ public async Task RestoreAsync_UnchangedValueAsValue_DoesNotPushToRestoreService
Assert.Equal(1, callCount); // Should have only been called once
}

[Theory]
[InlineData("DefiningProjectFullPath", @"C:\Project\references%3B.props", @"C:\Project\moved.props")]
[InlineData("DefiningProjectLineNumber", "3", "8")]
[InlineData("DefiningProjectColumnNumber", "5", "0")]
public async Task RestoreAsync_SourceMetadataChanges_Renominates(string metadataName, string before, string after)
{
var nominations = new List<ProjectRestoreInfo>();
var restoreService = INuGetRestoreServiceFactory.ImplementNominateProjectAsync((info, _, _) => nominations.Add(info));
var instance = CreateInitializedInstance(nugetRestoreService: restoreService);
var activeConfiguration = ProjectConfigurationFactory.Create("Debug|AnyCPU");

foreach (string metadataValue in new[] { before, before, after, "" })
{
var metadata = ImmutableDictionary<string, string>.Empty.Add("Version", "1.0.0").Add(metadataName, metadataValue);
var items = ImmutableDictionary<string, IImmutableDictionary<string, string>>.Empty.Add("Package", metadata);
var snapshot = IProjectRuleSnapshotFactory.Create(CollectedPackageReference.SchemaName, "Unused", "", items);
var update = ImmutableDictionary<string, IProjectRuleSnapshot>.Empty.Add(CollectedPackageReference.SchemaName, snapshot);
var restoreInfo = RestoreBuilder.ToProjectRestoreInfo(update);
var value = IProjectVersionedValueFactory.Create(new PackageRestoreUnconfiguredInput(restoreInfo, [], activeConfiguration));

await instance.RestoreAsync(value);
}

Assert.Equal(3, nominations.Count);
Assert.Equal(new[] { before, after, "" }, nominations.Select(info =>
Assert.Single(Assert.Single(info.TargetFrameworks).PackageReferences).Metadata[metadataName]));
}

private static PackageRestoreDataSource CreateInitializedInstance(UnconfiguredProject? project = null, IPackageRestoreUnconfiguredInputDataSource? dataSource = null, INuGetRestoreService? nugetRestoreService = null)
{
var instance = CreateInstance(project, dataSource, nugetRestoreService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public void EmbeddedRuleNames()
Assert.NotEmpty(s_embeddedRuleNames);
}

[Theory]
[InlineData("DefiningProjectFullPath")]
[InlineData("DefiningProjectLineNumber")]
[InlineData("DefiningProjectColumnNumber")]
public void CollectedPackageReferenceIncludesSourceMetadata(string metadataName)
{
var (fullPath, _) = GetRules().Single(rule => Path.GetFileNameWithoutExtension(rule.Path) == CollectedPackageReference.SchemaName);
var property = Assert.Single(GetProperties(LoadXamlRule(fullPath)), property => property.Attribute("Name")?.Value == metadataName);

Assert.Equal(XName.Get("StringProperty", MSBuildNamespace), property.Name);
Assert.Equal("true", property.Attribute("ReadOnly")?.Value);
Assert.False(IsVisible(property));
Assert.Null(GetDataSource(property));
}

[Theory]
[MemberData(nameof(GetEmbeddedRules))]
public void EmbeddedRulesShouldNotHaveVisibleProperties(string ruleName, string fullPath, Type assemblyExporterType)
Expand Down
Loading