Skip to content

Commit 850e934

Browse files
DavidKarlashalter73
authored andcommitted
Fixes #32028: Investigate Template Baseline tests errors
Latest `dotnet new` doesn't work with relative path for `--debug:custom-hive`... Hence make it absolute Also switched to using `--debug:disable-sdk-templates` to avoid potential conflict between SDK and tests installed templates.
1 parent cc57bb8 commit 850e934

File tree

2 files changed

+13
-51
lines changed

2 files changed

+13
-51
lines changed

src/ProjectTemplates/Shared/Project.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal async Task<ProcessResult> RunDotNetNewAsync(
5858
// Used to set special options in MSBuild
5959
IDictionary<string, string> environmentVariables = null)
6060
{
61-
var hiveArg = $"--debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
61+
var hiveArg = $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
6262
var argString = $"new {templateName} {hiveArg}";
6363
environmentVariables ??= new Dictionary<string, string>();
6464
if (!string.IsNullOrEmpty(auth))
@@ -323,7 +323,7 @@ internal async Task<ProcessEx> RunDotNetNewRawAsync(string arguments)
323323
AppContext.BaseDirectory,
324324
DotNetMuxer.MuxerPathOrDefault(),
325325
arguments +
326-
$" --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" +
326+
$" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" +
327327
$" -o {TemplateOutputDir}");
328328
await result.Exited;
329329
return result;

src/ProjectTemplates/Shared/TemplatePackageInstaller.cs

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ internal static class TemplatePackageInstaller
4343
"Microsoft.AspNetCore.Blazor.Templates",
4444
};
4545

46-
public static string CustomHivePath { get; } = (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix")))
46+
public static string CustomHivePath { get; } = Path.GetFullPath((string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix")))
4747
? typeof(TemplatePackageInstaller)
4848
.Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
4949
.Single(s => s.Key == "CustomTemplateHivePath").Value
50-
: Path.Combine("Hives", ".templateEngine");
50+
: Path.Combine("Hives", ".templateEngine"));
5151

5252
public static async Task EnsureTemplatingEngineInitializedAsync(ITestOutputHelper output)
5353
{
@@ -78,7 +78,9 @@ public static async Task<ProcessEx> RunDotNetNew(ITestOutputHelper output, strin
7878
output,
7979
AppContext.BaseDirectory,
8080
DotNetMuxer.MuxerPathOrDefault(),
81-
$"new {arguments} --debug:custom-hive \"{CustomHivePath}\"");
81+
//--debug:disable-sdk-templates means, don't include C:\Program Files\dotnet\templates, aka. what comes with SDK, so we don't need to uninstall
82+
//--debug:custom-hive means, don't install templates on CI/developer machine, instead create new temporary instance
83+
$"new {arguments} --debug:disable-sdk-templates --debug:custom-hive \"{CustomHivePath}\"");
8284

8385
await proc.Exited;
8486

@@ -105,23 +107,12 @@ private static async Task InstallTemplatePackages(ITestOutputHelper output)
105107

106108
Assert.Equal(4, builtPackages.Length);
107109

108-
/*
109-
* The templates are indexed by path, for example:
110-
&USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg
111-
Templates:
112-
NUnit 3 Test Project (nunit) C#
113-
NUnit 3 Test Item (nunit-test) C#
114-
NUnit 3 Test Project (nunit) F#
115-
NUnit 3 Test Item (nunit-test) F#
116-
NUnit 3 Test Project (nunit) VB
117-
NUnit 3 Test Item (nunit-test) VB
118-
Uninstall Command:
119-
dotnet new -u &USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg
120-
121-
* We don't want to construct this path so we'll rely on dotnet new --uninstall --help to construct the uninstall command.
122-
*/
123-
// Workaround for https://github.com/dotnet/sdk/issues/16906
124-
// await UninstallExistingTemplatesAsync(output);
110+
await VerifyCannotFindTemplateAsync(output, "web");
111+
await VerifyCannotFindTemplateAsync(output, "webapp");
112+
await VerifyCannotFindTemplateAsync(output, "mvc");
113+
await VerifyCannotFindTemplateAsync(output, "react");
114+
await VerifyCannotFindTemplateAsync(output, "reactredux");
115+
await VerifyCannotFindTemplateAsync(output, "angular");
125116

126117
foreach (var packagePath in builtPackages)
127118
{
@@ -135,35 +126,6 @@ NUnit 3 Test Item (nunit-test) VB
135126
await VerifyCanFindTemplate(output, "react");
136127
}
137128

138-
private static async Task UninstallExistingTemplatesAsync(ITestOutputHelper output)
139-
{
140-
var proc = await RunDotNetNew(output, "--uninstall --help");
141-
var lines = proc.Output.Split(Environment.NewLine);
142-
143-
// Remove any previous or prebundled version of the template packages
144-
foreach (var packageName in _templatePackages)
145-
{
146-
// Depending on the ordering, there may be multiple matches:
147-
// Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.3.0.0-preview7.*.nupkg
148-
// Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-preview7.*.nupkg
149-
// Error on the side of caution and uninstall all of them
150-
foreach (var command in lines.Where(l => l.Contains("dotnet new") && l.Contains(packageName, StringComparison.OrdinalIgnoreCase)))
151-
{
152-
var uninstallCommand = command.TrimStart();
153-
Debug.Assert(uninstallCommand.StartsWith("dotnet new", StringComparison.Ordinal));
154-
uninstallCommand = uninstallCommand.Substring("dotnet new".Length);
155-
await RunDotNetNew(output, uninstallCommand);
156-
}
157-
}
158-
159-
await VerifyCannotFindTemplateAsync(output, "web");
160-
await VerifyCannotFindTemplateAsync(output, "webapp");
161-
await VerifyCannotFindTemplateAsync(output, "mvc");
162-
await VerifyCannotFindTemplateAsync(output, "react");
163-
await VerifyCannotFindTemplateAsync(output, "reactredux");
164-
await VerifyCannotFindTemplateAsync(output, "angular");
165-
}
166-
167129
private static async Task VerifyCanFindTemplate(ITestOutputHelper output, string templateName)
168130
{
169131
var proc = await RunDotNetNew(output, $"");

0 commit comments

Comments
 (0)