From 991cf9789f9bc6a88f20a557d411522ba1b17c21 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 21 Apr 2025 16:17:25 +0200 Subject: [PATCH] Fix new exercise --- bin/add-practice-exercise.ps1 | 9 +++++++-- generators/TemplateGenerator.cs | 3 --- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/add-practice-exercise.ps1 b/bin/add-practice-exercise.ps1 index 3658e011c3..a6043717bd 100644 --- a/bin/add-practice-exercise.ps1 +++ b/bin/add-practice-exercise.ps1 @@ -33,18 +33,23 @@ $exerciseName = (Get-Culture).TextInfo.ToTitleCase($Exercise).Replace("-", "") $exerciseDir = "exercises/practice/${Exercise}" $projectFile = "${exerciseDir}/${ExerciseName}.csproj" & dotnet new install xunit.v3.templates -& dotnet new xunit3 --force --output $exerciseDir --name $ExerciseName +& dotnet new xunit3 --force --framework net9.0 --output $exerciseDir --name $ExerciseName & dotnet sln exercises/Exercises.sln add $projectFile [xml]$project = Get-Content $projectFile $project.Project.PropertyGroup.RemoveChild($project.Project.PropertyGroup.SelectSingleNode("//comment()")) $project.Project.PropertyGroup.RemoveChild($project.Project.PropertyGroup.SelectSingleNode("//RootNamespace")) +$restorePackagesWithLockFileElement = $project.CreateElement("RestorePackagesWithLockFile"); +$restorePackagesWithLockFileElement.InnerText = "true" +$project.Project.PropertyGroup.AppendChild($restorePackagesWithLockFileElement) $project.Project.RemoveChild($project.Project.ItemGroup[0]) $project.Project.ItemGroup[1].SelectSingleNode("PackageReference[@Include='Microsoft.NET.Test.Sdk']").SetAttribute("Version", "17.12.0") $project.Project.ItemGroup[1].SelectSingleNode("PackageReference[@Include='xunit.v3']").SetAttribute("Version", "1.1.0") -$project.Project.ItemGroup[1].SelectSingleNode("PackageReference[@Include='xunit.runner.visualstudio']").SetAttribute("Version", "3.0.2") +$project.Project.ItemGroup[1].SelectSingleNode("PackageReference[@Include='xunit.runner.visualstudio']").SetAttribute("Version", "3.0.1") $project.Save($projectFile) +dotnet add $projectFile package Exercism.Tests.xunit.v3 --version 0.1.0-beta1 + # Remove and update files Remove-Item -Path "${exerciseDir}/xunit.runner.json" Remove-Item -Path "${exerciseDir}/UnitTest1.cs" diff --git a/generators/TemplateGenerator.cs b/generators/TemplateGenerator.cs index 59d3078d54..bd3909159a 100644 --- a/generators/TemplateGenerator.cs +++ b/generators/TemplateGenerator.cs @@ -61,9 +61,6 @@ private static bool ExpectsError(this JsonNode testCase) => testCase["expected"] is JsonObject jsonObject && jsonObject.ContainsKey("error"); private const string GeneratorTemplate = @" -{{ if error }}using System;{{ end }} -using Xunit; - public class {%{{{ testClass }}}%} { {%{{{- for test in tests }}}%}