|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
4 | 4 | using System;
|
| 5 | +using System.Diagnostics; |
5 | 6 | using System.IO;
|
6 | 7 | using System.Linq;
|
7 | 8 | using System.Reflection;
|
@@ -30,10 +31,10 @@ internal static class TemplatePackageInstaller
|
30 | 31 | "Microsoft.DotNet.Web.ProjectTemplates.2.1",
|
31 | 32 | "Microsoft.DotNet.Web.ProjectTemplates.2.2",
|
32 | 33 | "Microsoft.DotNet.Web.ProjectTemplates.3.0",
|
33 |
| - "Microsoft.DotNet.Web.Spa.ProjectTemplates", |
34 | 34 | "Microsoft.DotNet.Web.Spa.ProjectTemplates.2.1",
|
35 | 35 | "Microsoft.DotNet.Web.Spa.ProjectTemplates.2.2",
|
36 |
| - "Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0" |
| 36 | + "Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0", |
| 37 | + "Microsoft.DotNet.Web.Spa.ProjectTemplates" |
37 | 38 | };
|
38 | 39 |
|
39 | 40 | public static string CustomHivePath { get; } = typeof(TemplatePackageInstaller)
|
@@ -85,13 +86,38 @@ private static async Task InstallTemplatePackages(ITestOutputHelper output)
|
85 | 86 |
|
86 | 87 | Assert.Equal(4, builtPackages.Length);
|
87 | 88 |
|
| 89 | + /* |
| 90 | + * The templates are indexed by path, for example: |
| 91 | + &USERPROFILE%\.templateengine\dotnetcli\v3.0.100-preview7-012821\packages\nunit3.dotnetnew.template.1.6.1.nupkg |
| 92 | + Templates: |
| 93 | + NUnit 3 Test Project (nunit) C# |
| 94 | + NUnit 3 Test Item (nunit-test) C# |
| 95 | + NUnit 3 Test Project (nunit) F# |
| 96 | + NUnit 3 Test Item (nunit-test) F# |
| 97 | + NUnit 3 Test Project (nunit) VB |
| 98 | + NUnit 3 Test Item (nunit-test) VB |
| 99 | + Uninstall Command: |
| 100 | + dotnet new -u &USERPROFILE%\.templateengine\dotnetcli\v3.0.100-preview7-012821\packages\nunit3.dotnetnew.template.1.6.1.nupkg |
| 101 | +
|
| 102 | + * We don't want to construct this path so we'll rely on dotnet new --uninstall --help to construct the uninstall command. |
| 103 | + */ |
| 104 | + var proc = await RunDotNetNew(output, "--uninstall --help"); |
| 105 | + var lines = proc.Output.Split(Environment.NewLine); |
| 106 | + |
88 | 107 | // Remove any previous or prebundled version of the template packages
|
89 | 108 | foreach (var packageName in _templatePackages)
|
90 | 109 | {
|
91 |
| - // We don't need this command to succeed, because we'll verify next that |
92 |
| - // uninstallation had the desired effect. This command is expected to fail |
93 |
| - // in the case where the package wasn't previously installed. |
94 |
| - await RunDotNetNew(output, $"--uninstall {packageName}"); |
| 110 | + // Depending on the ordering, there may be multiple matches: |
| 111 | + // Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.3.0.0-preview7.*.nupkg |
| 112 | + // Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-preview7.*.nupkg |
| 113 | + // Error on the side of caution and uninstall all of them |
| 114 | + foreach (var command in lines.Where(l => l.Contains("dotnet new") && l.Contains(packageName, StringComparison.OrdinalIgnoreCase))) |
| 115 | + { |
| 116 | + var uninstallCommand = command.TrimStart(); |
| 117 | + Debug.Assert(uninstallCommand.StartsWith("dotnet new")); |
| 118 | + uninstallCommand = uninstallCommand.Substring("dotnet new".Length); |
| 119 | + await RunDotNetNew(output, uninstallCommand); |
| 120 | + } |
95 | 121 | }
|
96 | 122 |
|
97 | 123 | await VerifyCannotFindTemplateAsync(output, "web");
|
@@ -132,7 +158,7 @@ private static async Task VerifyCannotFindTemplateAsync(ITestOutputHelper output
|
132 | 158 | {
|
133 | 159 | var proc = await RunDotNetNew(output, $"\"{templateName}\"");
|
134 | 160 |
|
135 |
| - if (!proc.Error.Contains($"No templates matched the input template name: {templateName}.")) |
| 161 | + if (!proc.Output.Contains("Couldn't find an installed template that matches the input, searching online for one that does...")) |
136 | 162 | {
|
137 | 163 | throw new InvalidOperationException($"Failed to uninstall previous templates. The template '{templateName}' could still be found.");
|
138 | 164 | }
|
|
0 commit comments