Skip to content

Commit d1a529f

Browse files
authored
Use different delimiter for message pack formatter, allow for out of proc calls to work, add message pack serialization annotations (#7096)
1 parent 8b3572f commit d1a529f

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/NuGet.Clients/NuGet.VisualStudio.Contracts/InstalledPackagesResult.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
#nullable disable
55

66
using System.Collections.Generic;
7+
using MessagePack;
78

89
namespace NuGet.VisualStudio.Contracts
910
{
1011
/// <summary>Result of a call to <see cref="INuGetProjectService.GetInstalledPackagesAsync"/></summary>
1112
/// <remarks>To create an instance, use <see cref="NuGetContractsFactory.CreateInstalledPackagesResult"/>.</remarks>
13+
[MessagePackObject]
1214
public sealed class InstalledPackagesResult
1315
{
1416
/// <summary>The status of the result</summary>
17+
[Key(0)]
1518
public InstalledPackageResultStatus Status { get; }
1619

1720
/// <summary>List of packages in the project</summary>
1821
/// <remarks>May be null if <see cref="Status"/> was not successful</remarks>
22+
[Key(1)]
1923
public IReadOnlyCollection<NuGetInstalledPackage> Packages { get; }
2024

2125
// This class will hopefully use C# record types when that language feature becomes available, so make the constructor not-public, to prevent breaking change when records come out.

src/NuGet.Clients/NuGet.VisualStudio.Contracts/NuGet.VisualStudio.Contracts.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
<!-- We do this to avoid the warning our build raises about keeping a consistent newtonsoft.json version. We don't need newtonsonft.json type in here, we don't use it. -->
2626
<PackageReference Include="Newtonsoft.Json" PrivateAssets="all" ExcludeAssets="all" />
2727
</ItemGroup>
28+
29+
<ItemGroup>
30+
<InternalsVisibleTo Include="NuGet.VisualStudio.Implementation.Test" />
31+
</ItemGroup>
2832
</Project>

src/NuGet.Clients/NuGet.VisualStudio.Contracts/NuGetInstalledPackage.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
#nullable disable
55

6+
using MessagePack;
7+
68
namespace NuGet.VisualStudio.Contracts
79
{
810
/// <summary>Information about an installed package</summary>
911
/// <remarks>To create an instance, use <see cref="NuGetContractsFactory.CreateNuGetInstalledPackage"/>.</remarks>
12+
[MessagePackObject]
1013
public sealed class NuGetInstalledPackage
1114
{
1215
/// <summary>The package id.</summary>
16+
[Key(0)]
1317
public string Id { get; }
1418

1519
/// <summary>The project's requested package range for the package.</summary>
@@ -18,6 +22,7 @@ public sealed class NuGetInstalledPackage
1822
/// If the project uses PackageReference, this is the version string in the project file, which may not match the resolved package version, and may be a range, not a single version.<br/>
1923
/// If the project uses PackageReference, and the package is a transitive dependency, the value will be null.
2024
/// </remarks>
25+
[Key(1)]
2126
public string RequestedRange { get; }
2227

2328
/// <summary>The installed package version</summary>
@@ -26,18 +31,21 @@ public sealed class NuGetInstalledPackage
2631
/// <para>If the project uses PackageReference, this will be the resolved version, if the project has been restored successfully.
2732
/// In some error conditions this may be an empty string.</para>
2833
/// </remarks>
34+
[Key(2)]
2935
public string Version { get; }
3036

3137
/// <summary>Path to the extracted package</summary>
3238
/// <remarks>
3339
/// This may be null if the package was not restored successfully.
3440
/// </remarks>
41+
[Key(3)]
3542
public string InstallPath { get; }
3643

3744
/// <summary>This package a direct dependency of the project</summary>
3845
/// <remarks>
3946
/// packages.config do not support transitive dependencies, so all packages will have this property set to true, even if the package was installed because it was a dependency of a package that the customer selected for install.
4047
/// </remarks>
48+
[Key(4)]
4149
public bool DirectDependency { get; }
4250

4351
// This class will hopefully use C# record types when that language feature becomes available, so make the constructor not-public, to prevent breaking change when records come out.

src/NuGet.Clients/NuGet.VisualStudio.Contracts/NuGetServices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public static class NuGetServices
2020
public static ServiceRpcDescriptor NuGetProjectServiceV1 { get; } = new ServiceJsonRpcDescriptor(
2121
new ServiceMoniker(NuGetProjectServiceName, new System.Version(Version1)),
2222
ServiceJsonRpcDescriptor.Formatters.MessagePack,
23-
ServiceJsonRpcDescriptor.MessageDelimiters.HttpLikeHeaders);
23+
ServiceJsonRpcDescriptor.MessageDelimiters.BigEndianInt32LengthHeader);
2424
}
2525
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Microsoft.VisualStudio.Sdk.TestFramework;
8+
using NuGet.VisualStudio.Contracts;
9+
using Xunit;
10+
using Xunit.Abstractions;
11+
12+
public class NuGetProjectServiceV1ContractTests : BrokeredServiceContractTestBase<INuGetProjectService, NuGetProjectServiceWithDummyValues>
13+
{
14+
public NuGetProjectServiceV1ContractTests(ITestOutputHelper logger) : base(logger, NuGetServices.NuGetProjectServiceV1) { }
15+
16+
[Fact]
17+
public async Task GetInstalledPackagesAsync_Serialization_Succeeds()
18+
{
19+
await ClientProxy.GetInstalledPackagesAsync(new Guid(), TimeoutToken);
20+
}
21+
}
22+
23+
public class NuGetProjectServiceWithDummyValues : INuGetProjectService
24+
{
25+
public Task<InstalledPackagesResult> GetInstalledPackagesAsync(Guid projectId, CancellationToken cancellationToken)
26+
{
27+
return Task.FromResult(NuGetContractsFactory.CreateInstalledPackagesResult(
28+
InstalledPackageResultStatus.Successful,
29+
[
30+
new NuGetInstalledPackage("TestPackage", "1.0.0", "1.0.0", @"C:\TestPackagePath", true),
31+
new NuGetInstalledPackage("SomeTestPackage", "2.0.0", "1.0.0", @"C:\SomeTestPackage", false),
32+
new NuGetInstalledPackage("AnotherTestPackage", "1.0.0", "10.0.0", @"C:\AnotherTestPackage", true)
33+
]));
34+
}
35+
}

0 commit comments

Comments
 (0)