Skip to content

Commit dd04ba3

Browse files
authored
Update MSTest template.json to create dotnet.config (#50482)
1 parent 705a211 commit dd04ba3

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-CSharp/.template.config/template.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@
227227
"id": "restoreNugetPackages",
228228
"continueOnError": true
229229
},
230+
{
231+
"condition": "(TestRunner == \"Microsoft.Testing.Platform\")",
232+
"description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.",
233+
"manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }],
234+
"actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97",
235+
"id": "createOrUpdateDotnetConfig",
236+
"args": {
237+
"section": "dotnet.test.runner",
238+
"key": "name",
239+
"value": "Microsoft.Testing.Platform",
240+
},
241+
"continueOnError": true
242+
},
230243
{
231244
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
232245
"description": "Opens Test1.cs in the editor",

template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-FSharp/.template.config/template.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@
227227
"id": "restoreNugetPackages",
228228
"continueOnError": true
229229
},
230+
{
231+
"condition": "(TestRunner == \"Microsoft.Testing.Platform\")",
232+
"description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.",
233+
"manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }],
234+
"actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97",
235+
"id": "createOrUpdateDotnetConfig",
236+
"args": {
237+
"section": "dotnet.test.runner",
238+
"key": "name",
239+
"value": "Microsoft.Testing.Platform",
240+
},
241+
"continueOnError": true
242+
},
230243
{
231244
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
232245
"description": "Opens Test1.fs in the editor",

template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/MSTest-VisualBasic/.template.config/template.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@
227227
"id": "restoreNugetPackages",
228228
"continueOnError": true
229229
},
230+
{
231+
"condition": "(TestRunner == \"Microsoft.Testing.Platform\")",
232+
"description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.",
233+
"manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }],
234+
"actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97",
235+
"id": "createOrUpdateDotnetConfig",
236+
"args": {
237+
"section": "dotnet.test.runner",
238+
"key": "name",
239+
"value": "Microsoft.Testing.Platform",
240+
},
241+
"continueOnError": true
242+
},
230243
{
231244
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
232245
"description": "Opens Test1.vb in the editor",

template_feed/Microsoft.DotNet.Common.ProjectTemplates.10.0/content/Playwright-MSTest-CSharp/.template.config/template.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@
247247
"id": "restoreNugetPackages",
248248
"continueOnError": true
249249
},
250+
{
251+
"condition": "(TestRunner == \"Microsoft.Testing.Platform\")",
252+
"description": "Create or update 'dotnet.config' file required by Microsoft.Testing.Platform.",
253+
"manualInstructions": [{ "text": "Manually create 'dotnet.config' file setting the test runner to Microsoft.Testing.Platform" }],
254+
"actionId": "597E7933-0D87-452C-B094-8FA0EEF7FD97",
255+
"id": "createOrUpdateDotnetConfig",
256+
"args": {
257+
"section": "dotnet.test.runner",
258+
"key": "name",
259+
"value": "Microsoft.Testing.Platform",
260+
},
261+
"continueOnError": true
262+
},
250263
{
251264
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
252265
"description": "Opens Test1.cs in the editor",

test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can
180180
{
181181
string testProjectName = GenerateTestProjectName();
182182
string outputDirectory = CreateTemporaryFolder(folderName: "Home");
183+
184+
// Prevent the dotnet.config post action from walking up the directory parents up to our own solution root, which would affect other tests.
185+
Directory.CreateDirectory(Path.Combine(outputDirectory, ".git"));
186+
183187
string workingDirectory = CreateTemporaryFolder();
184188

185189
// Create new test project: dotnet new <projectTemplate> -n <testProjectName> -f <targetFramework> -lang <language> --coverage-tool <coverageTool> --test-runner <testRunner>
@@ -196,10 +200,7 @@ public void MSTestAndPlaywrightProjectTemplate_WithCoverageToolAndTestRunner_Can
196200
var isMTP = testRunner == "Microsoft.Testing.Platform";
197201
if (isMTP)
198202
{
199-
File.WriteAllText(Path.Combine(outputDirectory, "dotnet.config"), """
200-
[dotnet.test.runner]
201-
name = "Microsoft.Testing.Platform"
202-
""");
203+
File.Exists(Path.Combine(outputDirectory, "dotnet.config")).Should().BeTrue();
203204
}
204205

205206
var result = new DotnetTestCommand(_log, false)

0 commit comments

Comments
 (0)