diff --git a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-CSharp/.template.config/template.json b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-CSharp/.template.config/template.json index 07997ec3dc7b..95b01952003c 100644 --- a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-CSharp/.template.config/template.json +++ b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-CSharp/.template.config/template.json @@ -227,6 +227,19 @@ "id": "restoreNugetPackages", "continueOnError": true }, + { + "condition": "(TestRunner == \"Microsoft.Testing.Platform\")", + "description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.", + "manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }], + "actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97", + "id": "createOrUpdateDotnetConfig", + "args": { + "section": "dotnet.test.runner", + "key": "name", + "value": "Microsoft.Testing.Platform", + }, + "continueOnError": true + }, { "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", "description": "Opens Test1.cs in the editor", diff --git a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-FSharp/.template.config/template.json b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-FSharp/.template.config/template.json index 5a4bd0d319ad..d7f018f5efc6 100644 --- a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-FSharp/.template.config/template.json +++ b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-FSharp/.template.config/template.json @@ -227,6 +227,19 @@ "id": "restoreNugetPackages", "continueOnError": true }, + { + "condition": "(TestRunner == \"Microsoft.Testing.Platform\")", + "description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.", + "manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }], + "actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97", + "id": "createOrUpdateDotnetConfig", + "args": { + "section": "dotnet.test.runner", + "key": "name", + "value": "Microsoft.Testing.Platform", + }, + "continueOnError": true + }, { "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", "description": "Opens Test1.fs in the editor", diff --git a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-VisualBasic/.template.config/template.json b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-VisualBasic/.template.config/template.json index e28607d44627..71fe6ea96124 100644 --- a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-VisualBasic/.template.config/template.json +++ b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-VisualBasic/.template.config/template.json @@ -227,6 +227,19 @@ "id": "restoreNugetPackages", "continueOnError": true }, + { + "condition": "(TestRunner == \"Microsoft.Testing.Platform\")", + "description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.", + "manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }], + "actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97", + "id": "createOrUpdateDotnetConfig", + "args": { + "section": "dotnet.test.runner", + "key": "name", + "value": "Microsoft.Testing.Platform", + }, + "continueOnError": true + }, { "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", "description": "Opens Test1.vb in the editor", diff --git a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/Playwright-MSTest-CSharp/.template.config/template.json b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/Playwright-MSTest-CSharp/.template.config/template.json index 7e7675f46448..303570a8da7a 100644 --- a/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/Playwright-MSTest-CSharp/.template.config/template.json +++ b/template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/Playwright-MSTest-CSharp/.template.config/template.json @@ -247,6 +247,19 @@ "id": "restoreNugetPackages", "continueOnError": true }, + { + "condition": "(TestRunner == \"Microsoft.Testing.Platform\")", + "description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.", + "manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }], + "actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97", + "id": "createOrUpdateDotnetConfig", + "args": { + "section": "dotnet.test.runner", + "key": "name", + "value": "Microsoft.Testing.Platform", + }, + "continueOnError": true + }, { "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", "description": "Opens Test1.cs in the editor", diff --git a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs index 0bac03c7e9a3..b50ea3706216 100644 --- a/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs +++ b/test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs @@ -180,6 +180,10 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can { string testProjectName = GenerateTestProjectName(); string outputDirectory = CreateTemporaryFolder(folderName: "Home"); + + // Prevent the dotnet.config post action from walking up the directory parents up to our own solution root, which would affect other tests. + Directory.CreateDirectory(Path.Combine(outputDirectory, ".git")); + string workingDirectory = CreateTemporaryFolder(); // Create new test project: dotnet new -n -f -lang --coverage-tool --test-runner @@ -196,10 +200,7 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can var isMTP = testRunner == "Microsoft.Testing.Platform"; if (isMTP) { - File.WriteAllText(Path.Combine(outputDirectory, "dotnet.config"), """ - [dotnet.test.runner] - name = "Microsoft.Testing.Platform" - """); + File.Exists(Path.Combine(outputDirectory, "dotnet.config")).Should().BeTrue(); } var result = new DotnetTestCommand(_log, false)