Skip to content
Open
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
25 changes: 24 additions & 1 deletion src/VsixTesting.Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,36 @@ internal class Program : MarshalByRefObject
[STAThread]
public static int Main(string[] args)
{
var applicationPath = CommandLineParser.One(args, "ApplicationPath");
var applicationPath = CommandLineParser.One(args, "ApplicationPath", string.Empty);
var rootSuffix = CommandLineParser.One(args, "RootSuffix", string.Empty);

if (string.IsNullOrEmpty(applicationPath))
{
var version = CommandLineParser.One(args, "Version");
var sku = CommandLineParser.One(args, "SKU", string.Empty);
var preview = CommandLineParser.Contains(args, "Preview");
var installations = VisualStudioUtil.FindInstallations();
applicationPath = GetInstallation(installations, version, sku, preview).ApplicationPath;
}

var appDomain = CreateAppDomain(applicationPath);
var program = appDomain.CreateInstanceFromAndUnwrap<Program>();
return program.Run(applicationPath, rootSuffix, args);
}

internal static VsInstallation GetInstallation(IEnumerable<VsInstallation> installations, string versionRange, string sku, bool preview)
{
var version = VersionRange.Parse(versionRange).Minimum;
var year = VersionUtil.GetYear(version);

return installations.
Where(i => i.Version.Major == version.Major)
.OrderByDescending(i => i.ProductId.Split('.').Last().Equals(sku, StringComparison.OrdinalIgnoreCase))
.ThenByDescending(i => i.Preview == preview)
.FirstOrDefault()
?? throw new Exception($"Please install Visual Studio {year}.");
}

private int Run(string applicationPath, string rootSuffix, string[] args)
{
try
Expand Down
10 changes: 5 additions & 5 deletions src/VsixTesting.Installer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
},
"VsixTesting.Installer.2012.Install": {
"commandName": "Project",
"commandLineArgs": "/ApplicationPath \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\devenv.exe\" /RootSuffix Exp /Install \"$(SolutionDir)bin\\VsixTesting.Invoker\\$(Configuration)\\net452\\VsixTesting.Invoker.vsix\""
"commandLineArgs": "/Version 2012 /RootSuffix Exp /Install \"$(SolutionDir)bin\\VsixTesting.Invoker\\$(Configuration)\\net452\\VsixTesting.Invoker.vsix\""
},
"VsixTesting.Installer.2012.InstallAndStart": {
"commandName": "Project",
"commandLineArgs": "/ApplicationPath \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\devenv.exe\" /RootSuffix Exp /InstallAndStart \"$(SolutionDir)bin\\VsixTesting.Invoker\\$(Configuration)\\net452\\VsixTesting.Invoker.vsix\""
"commandLineArgs": "/Version 2012 /RootSuffix Exp /InstallAndStart \"$(SolutionDir)bin\\VsixTesting.Invoker\\$(Configuration)\\net452\\VsixTesting.Invoker.vsix\""
},
"VsixTesting.Installer.2012.Uninstall": {
"commandName": "Project",
"commandLineArgs": "/ApplicationPath \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\devenv.exe\" /RootSuffix Exp /Uninstall 9eef3d53-333f-4be2-900e-a1f104fc325a"
"commandLineArgs": "/Version 2012 /RootSuffix Exp /Uninstall 9eef3d53-333f-4be2-900e-a1f104fc325a"
},
"VsixTesting.Installer.2012.IsProfileInitialized": {
"commandName": "Project",
"commandLineArgs": "/ApplicationPath \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\devenv.exe\" /RootSuffix Exp /IsProfileInitialized"
}
"commandLineArgs": "/Version 2012 /RootSuffix Exp /IsProfileInitialized"
},
}
}
2 changes: 1 addition & 1 deletion src/VsixTesting.Xunit/Internal/VsTestCaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal static IEnumerable<VsInstallation> FilterInstallations(IEnumerable<VsIn
{
foreach (var installation in group
.OrderBy(i => !i.ApplicationPath.Equals(preferedAppPath, StringComparison.OrdinalIgnoreCase))
.ThenBy(i => i.Name.Contains("-pre")))
.ThenBy(i => i.Preview))
{
if (!settings.SupportedVersionRanges.Any(range => installation.Version >= range.Minimum && installation.Version <= range.Maximum))
{
Expand Down
5 changes: 3 additions & 2 deletions src/VsixTesting/Vs/VersionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static int GetYear(Version version)
case 15: return 2017;
}

throw new ArgumentOutOfRangeException(nameof(version));
throw new ArgumentOutOfRangeException(nameof(version), $"Visual Studio {version.Major} is not supported.");
}

public static Version FromYear(int year)
Expand All @@ -27,8 +27,9 @@ public static Version FromYear(int year)
case 2013: return new Version(12, 0);
case 2015: return new Version(14, 0);
case 2017: return new Version(15, 0);
default: throw new ArgumentOutOfRangeException(nameof(year), $"VS{year} is not supported.");
}

throw new ArgumentOutOfRangeException(nameof(year), $"Visual Studio {year} is not supported.");
}
}
}
3 changes: 1 addition & 2 deletions src/VsixTesting/Vs/VisualStudioUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ namespace Vs
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Common;
using EnvDTE80;
using Microsoft.VisualStudio.Setup.Configuration;
using Microsoft.Win32;
using VsixTesting.Utilities;
using DTE = EnvDTE.DTE;

internal static partial class VisualStudioUtil
Expand Down Expand Up @@ -129,6 +127,7 @@ public static IEnumerable<VsInstallation> FindInstallations()
path: instance.GetInstallationPath())
{
PackageIds = instance.GetPackages().Select(p => p.GetId()),
ProductId = instance.GetProduct().GetId(),
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/VsixTesting/Vs/VsInstallation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public VsInstallation(Version version, string path, string name)
}

public Version Version { get; }
public bool Preview => Name.Contains("-pre");
public string Path { get; }
public string Name { get; }
public string ProductId { get; set; } = string.Empty;
public string ApplicationPath => VisualStudioUtil.GetApplicationPath(Path);
public IEnumerable<string> PackageIds { get; set; } = Enumerable.Empty<string>();
}
Expand Down
36 changes: 36 additions & 0 deletions test/VsixTesting.Installer.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2018 Jose Torres. All rights reserved. Licensed under the Apache License, Version 2.0. See LICENSE.md file in the project root for full license information.

namespace VsixTesting.Installer.Tests
{
using System;
using Vs;
using Xunit;

public class ProgramTests
{
private const string CommunityId = "Microsoft.VisualStudio.Product.Community";
private const string ProfessionalId = "Microsoft.VisualStudio.Product.Professional";
private const string EnterpriseId = "Microsoft.VisualStudio.Product.Enterprise";

[Theory]
[InlineData("2017", null, false, CommunityId)]
[InlineData("15.0", null, false, CommunityId)]
[InlineData("15", null, false, CommunityId)]
[InlineData("2017", null, true, ProfessionalId)]
[InlineData("2017", "Community", false, CommunityId)]
[InlineData("2017", "Community", true, CommunityId)]
[InlineData("2017", "Professional", false, ProfessionalId)]
[InlineData("2017", "Professional", true, ProfessionalId)]
void GetInstallation(string version, string sku, bool preview, string expected)
{
var installations = new[]
{
new VsInstallation(new Version(15, 0), string.Empty, "VisualStudio/15.0.0") { ProductId = CommunityId },
new VsInstallation(new Version(15, 0), string.Empty, "VisualStudio/15.0.0-pre.1.0+27729.1") { ProductId = ProfessionalId },
new VsInstallation(new Version(15, 1), string.Empty, "VisualStudio/15.0.1") { ProductId = EnterpriseId },
};

Assert.Equal(expected, Program.GetInstallation(installations, version, sku, preview).ProductId);
}
}
}