Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/ProjectTemplates/Shared/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal async Task<ProcessResult> RunDotNetNewAsync(
// Used to set special options in MSBuild
IDictionary<string, string> environmentVariables = null)
{
var hiveArg = $"--debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
var hiveArg = $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
var argString = $"new {templateName} {hiveArg}";
environmentVariables ??= new Dictionary<string, string>();
if (!string.IsNullOrEmpty(auth))
Expand Down Expand Up @@ -323,7 +323,7 @@ internal async Task<ProcessEx> RunDotNetNewRawAsync(string arguments)
AppContext.BaseDirectory,
DotNetMuxer.MuxerPathOrDefault(),
arguments +
$" --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" +
$" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" +
$" -o {TemplateOutputDir}");
await result.Exited;
return result;
Expand Down
60 changes: 11 additions & 49 deletions src/ProjectTemplates/Shared/TemplatePackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ internal static class TemplatePackageInstaller
"Microsoft.AspNetCore.Blazor.Templates",
};

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

public static async Task EnsureTemplatingEngineInitializedAsync(ITestOutputHelper output)
{
Expand Down Expand Up @@ -78,7 +78,9 @@ public static async Task<ProcessEx> RunDotNetNew(ITestOutputHelper output, strin
output,
AppContext.BaseDirectory,
DotNetMuxer.MuxerPathOrDefault(),
$"new {arguments} --debug:custom-hive \"{CustomHivePath}\"");
//--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
//--debug:custom-hive means, don't install templates on CI/developer machine, instead create new temporary instance
$"new {arguments} --debug:disable-sdk-templates --debug:custom-hive \"{CustomHivePath}\"");

await proc.Exited;

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

Assert.Equal(4, builtPackages.Length);

/*
* The templates are indexed by path, for example:
&USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg
Templates:
NUnit 3 Test Project (nunit) C#
NUnit 3 Test Item (nunit-test) C#
NUnit 3 Test Project (nunit) F#
NUnit 3 Test Item (nunit-test) F#
NUnit 3 Test Project (nunit) VB
NUnit 3 Test Item (nunit-test) VB
Uninstall Command:
dotnet new -u &USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg

* We don't want to construct this path so we'll rely on dotnet new --uninstall --help to construct the uninstall command.
*/
// Workaround for https://github.com/dotnet/sdk/issues/16906
// await UninstallExistingTemplatesAsync(output);
await VerifyCannotFindTemplateAsync(output, "web");
await VerifyCannotFindTemplateAsync(output, "webapp");
await VerifyCannotFindTemplateAsync(output, "mvc");
await VerifyCannotFindTemplateAsync(output, "react");
await VerifyCannotFindTemplateAsync(output, "reactredux");
await VerifyCannotFindTemplateAsync(output, "angular");

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

private static async Task UninstallExistingTemplatesAsync(ITestOutputHelper output)
{
var proc = await RunDotNetNew(output, "--uninstall --help");
var lines = proc.Output.Split(Environment.NewLine);

// Remove any previous or prebundled version of the template packages
foreach (var packageName in _templatePackages)
{
// Depending on the ordering, there may be multiple matches:
// Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.3.0.0-preview7.*.nupkg
// Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-preview7.*.nupkg
// Error on the side of caution and uninstall all of them
foreach (var command in lines.Where(l => l.Contains("dotnet new") && l.Contains(packageName, StringComparison.OrdinalIgnoreCase)))
{
var uninstallCommand = command.TrimStart();
Debug.Assert(uninstallCommand.StartsWith("dotnet new", StringComparison.Ordinal));
uninstallCommand = uninstallCommand.Substring("dotnet new".Length);
await RunDotNetNew(output, uninstallCommand);
}
}

await VerifyCannotFindTemplateAsync(output, "web");
await VerifyCannotFindTemplateAsync(output, "webapp");
await VerifyCannotFindTemplateAsync(output, "mvc");
await VerifyCannotFindTemplateAsync(output, "react");
await VerifyCannotFindTemplateAsync(output, "reactredux");
await VerifyCannotFindTemplateAsync(output, "angular");
}

private static async Task VerifyCanFindTemplate(ITestOutputHelper output, string templateName)
{
var proc = await RunDotNetNew(output, $"");
Expand Down