forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scan all kernels to find the nuget package
- Loading branch information
Showing
5 changed files
with
89 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Microsoft.DotNet.Interactive.SqlServer/SqlToolsServiceDiscovery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.DotNet.Interactive.SqlServer | ||
{ | ||
internal static class SqlToolsServiceDiscovery | ||
{ | ||
public static ResolvedPackageReference FindResolvedPackageReference(this Kernel rootKernel) | ||
{ | ||
var runtimePackageIdSuffix = "native.Microsoft.SqlToolsService"; | ||
foreach (var kernel in rootKernel.SubkernelsAndSelf().OfType<ISupportNuget>()) | ||
{ | ||
var resolvedPackageReferences = kernel.ResolvedPackageReferences; | ||
|
||
// Walk through the packages looking for the package that ends with the name "Microsoft.SqlToolsService" | ||
// and grab the packageroot | ||
|
||
var resolved = resolvedPackageReferences.FirstOrDefault(p => p.PackageName.EndsWith(runtimePackageIdSuffix, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (resolved is { }) | ||
{ | ||
return resolved; | ||
} | ||
|
||
} | ||
; | ||
return null; | ||
} | ||
|
||
public static string PathToService(this ResolvedPackageReference resolvedPackageReference, string serviceName) | ||
{ | ||
var pathToService = ""; | ||
if (resolvedPackageReference is not null) | ||
{ | ||
// Extract the platform 'osx-x64' from the package name 'runtime.osx-x64.native.microsoft.sqltoolsservice' | ||
string[] packageNameSegments = resolvedPackageReference.PackageName.Split("."); | ||
if (packageNameSegments.Length > 2) | ||
{ | ||
string platform = packageNameSegments[1]; | ||
|
||
// Build the path to the MicrosoftSqlToolsServiceLayer executable by reaching into the resolve nuget package | ||
// assuming a convention for native binaries. | ||
pathToService = Path.Combine( | ||
resolvedPackageReference.PackageRoot, | ||
"runtimes", | ||
platform, | ||
"native", | ||
serviceName); | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
pathToService += ".exe"; | ||
} | ||
} | ||
} | ||
|
||
return pathToService; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters