Skip to content

Commit

Permalink
Make powershell call .NET Core compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Feb 15, 2017
1 parent 4383671 commit 2973558
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/find-vs2017.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function tryVS7_COM (gyp) {
try {
const csFile = path.join(__dirname, '..', 'tools', 'Get-VS7.cs');
const cmd = 'powershell -ExecutionPolicy Unrestricted -Command ' +
'"&{ Add-Type -Path ' + csFile + '; [VisualStudioConfiguration.Program]::Main(@())}"'
'"&{ Add-Type -Path \'' + csFile + '\'; [VisualStudioConfiguration.Main]::Query()}"'
const vsSetupRaw = cp.execSync(cmd).toString();
if (!vsSetupRaw) return;
const vsSetup = vsSetupRaw.split(/[\r|\n]/g).reduce((s, l) => {
Expand Down Expand Up @@ -69,6 +69,6 @@ function setGypVS2017Env(gyp, callback) {

gyp.opts.msvs_version = '2017';
process.env['vs2017_install'] = vsSetup.InstallationPath;
process.env['vs2017_sdk'] = vsSetup.SDK.replace(/\d+$/, '0')
if (vsSetup.SDK) process.env['vs2017_sdk'] = vsSetup.SDK.replace(/\d+$/, '0')
callback();
}
43 changes: 16 additions & 27 deletions tools/Get-VS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public interface ISetupPropertyStore

[Guid("42843719-DB4C-46C2-8E7C-64F1816EFD5B")]
[CoClass(typeof(SetupConfigurationClass))]
[TypeLibImportClass(typeof(SetupConfigurationClass))]
[ComImport]
public interface SetupConfiguration : ISetupConfiguration2, ISetupConfiguration
{
Expand All @@ -176,36 +175,27 @@ public class SetupConfigurationClass
{
}

public static class Program
public static class Main
{
public static int Main(string[] args)
public static void Query()
{
try
{
ISetupConfiguration query = new SetupConfiguration();
ISetupConfiguration2 query2 = (ISetupConfiguration2) query;
IEnumSetupInstances e = query2.EnumAllInstances();
ISetupInstance2[] rgelt = new ISetupInstance2[1];
int pceltFetched;
do
{
e.Next(1, rgelt, out pceltFetched);
if (pceltFetched > 0)
PrintInstance(rgelt[0]);
} while (pceltFetched > 0);
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine("Error 0x{0:x8}: {1}", ex, ex.Message);
return 1;
}
ISetupConfiguration query = new SetupConfiguration();
ISetupConfiguration2 query2 = (ISetupConfiguration2) query;
IEnumSetupInstances e = query2.EnumAllInstances();
ISetupInstance2[] rgelt = new ISetupInstance2[1];
int pceltFetched;
do
{
e.Next(1, rgelt, out pceltFetched);
if (pceltFetched > 0)
PrintInstance(rgelt[0]);
} while (pceltFetched > 0);
}

private static void PrintInstance(ISetupInstance2 setupInstance2)
{
Console.WriteLine("InstallationPath: {0}", setupInstance2.GetInstallationPath());
Console.WriteLine("Product: {0}", setupInstance2.GetProduct().GetId());
Console.Write(String.Format("InstallationPath: {0}\n", setupInstance2.GetInstallationPath()));
Console.Write(String.Format("Product: {0}\n", setupInstance2.GetProduct().GetId()));
foreach (ISetupPackageReference package in setupInstance2.GetPackages())
{
if (package.GetType() != "Exe") continue;
Expand All @@ -216,9 +206,8 @@ private static void PrintInstance(ISetupInstance2 setupInstance2)
string sdkVer = parts[1];
char[] chars = {'1', '0', '8'};
if (sdkVer.IndexOfAny(chars) == -1) continue;
Console.WriteLine("SDK: {0}", sdkVer);
Console.Write(String.Format("SDK: {0}\n", sdkVer));
}
Console.WriteLine();
}
}
}

0 comments on commit 2973558

Please sign in to comment.