From 4421efc103bf5a0158234b0419490496fa66a8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 Jul 2022 11:29:53 +0200 Subject: [PATCH 1/8] build --- scripts/build.ps1 | 214 +++++++++++++----- test/CompatibilityTestAssets/NuGet.config | 16 ++ .../CompatibilityTestAssets.sln | 14 ++ .../MSTestProject1.csproj | 28 +++ .../UnitTest1.cs | 28 +++ test/GeneratedTestAssets/NuGet.config | 14 ++ test/TestAssets/NuGet.config | 14 -- test/TestAssets/TestAssets.sln | 14 -- test/TestAssets/Tools/Program.cs | 7 - test/TestAssets/Tools/Tools.csproj | 23 -- 10 files changed, 259 insertions(+), 113 deletions(-) create mode 100644 test/CompatibilityTestAssets/NuGet.config create mode 100644 test/GeneratedTestAssets/CompatibilityTestAssets.sln create mode 100644 test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj create mode 100644 test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs create mode 100644 test/GeneratedTestAssets/NuGet.config delete mode 100644 test/TestAssets/Tools/Program.cs delete mode 100644 test/TestAssets/Tools/Tools.csproj diff --git a/scripts/build.ps1 b/scripts/build.ps1 index c9e9cce891..19c9e333a4 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -78,6 +78,8 @@ Write-Verbose "Setup build configuration." $TPB_TestAssets = Join-Path $env:TP_ROOT_DIR "test\TestAssets\" $TPB_Solution = Join-Path $env:TP_ROOT_DIR "TestPlatform.sln" $TPB_TestAssets_Solution = Join-Path $TPB_TestAssets "TestAssets.sln" +$TPB_CompatibilityTestAssets = Join-Path $env:TP_ROOT_DIR "test\CompatibilityTestAssets\" +$TPB_CompatibilityTestAssets_Solution = Join-Path $TPB_CompatibilityTestAssets "TestAssets.sln" $TPB_TestAssets_CILAssets = Join-Path $TPB_TestAssets "CILProject\CILProject.proj" $TPB_TargetFramework462 = "net462" $TPB_TargetFramework472 = "net472" @@ -165,62 +167,131 @@ function Invoke-TestAssetsBuild { Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution -- add NuGet source" Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources add -Name ""locally-built-testplatform-packages"" -Source $env:TP_TESTARTIFACTS\packages\ -ConfigFile ""$nugetConfig""" Invoke-Exe $dotnetExe -Arguments "build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:""$env:TP_OUT_DIR\log\$Configuration\TestAssets.binlog""" + } + finally { + Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution -- remove NuGet source" + Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources remove -Name ""locally-built-testplatform-packages"" -ConfigFile ""$nugetConfig""" + } + Write-Log ".. .. Build: Complete." + Write-Log "Invoke-TestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}" +} - # Compatibility matrix build. - $dependenciesPath = "$env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props" - $dependenciesXml = [xml](Get-Content -Raw -Encoding UTF8 $dependenciesPath) - - # Restore previous versions of TestPlatform (for vstest.console.exe), and TestPlatform.CLI (for vstest.console.dll). - # These properties are coming from TestPlatform.Dependencies.props. - $vstestConsoleVersionProperties = @( - "VSTestConsoleLatestVersion" - "VSTestConsoleLatestPreviewVersion" - "VSTestConsoleLatestStableVersion" - "VSTestConsoleRecentStableVersion" - "VSTestConsoleMostDownloadedVersion" - "VSTestConsolePreviousStableVersion" - "VSTestConsoleLegacyStableVersion" - ) - - foreach ($propertyName in $vstestConsoleVersionProperties) { - if ("VSTestConsoleLatestVersion" -eq $propertyName) { - # NETTestSdkVersion has the version of the locally built package. - $vsTestConsoleVersion = $dependenciesXml.Project.PropertyGroup."NETTestSdkVersion" - } - else { - $vsTestConsoleVersion = $dependenciesXml.Project.PropertyGroup.$propertyName - } +function Invoke-CompatibilityTestAssetsBuild { + # Compatibility matrix build. + $dotnetExe = Get-DotNetPath + Write-Log "Invoke-CompatibilityTestAssetsBuild: Start test assets build." + $timer = Start-Timer + $generated = Join-Path (Split-Path -Path $TPB_TestAssets) -ChildPath "GeneratedTestAssets" + $generatedSln = Join-Path $generated "CompatibilityTestAssets.sln" + + # Figure out if the versions or the projects to build changed, and if they did not just + # and the solution is already in place just build it. + # Otherwise delete everything and regenerate and re-build. + $dependenciesPath = "$env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props" + $dependenciesXml = [xml](Get-Content -Raw -Encoding UTF8 $dependenciesPath) + + $cacheId = [ordered]@{ } + + # Restore previous versions of TestPlatform (for vstest.console.exe), and TestPlatform.CLI (for vstest.console.dll). + # These properties are coming from TestPlatform.Dependencies.props. + $vstestConsoleVersionProperties = @( + "VSTestConsoleLatestVersion" + "VSTestConsoleLatestPreviewVersion" + "VSTestConsoleLatestStableVersion" + "VSTestConsoleRecentStableVersion" + "VSTestConsoleMostDownloadedVersion" + "VSTestConsolePreviousStableVersion" + "VSTestConsoleLegacyStableVersion" + ) - # The command line tool does not like the package ranges. - $vsTestConsoleVersion = $vsTestConsoleVersion -replace "(\[|\])" - if (-not $vsTestConsoleVersion) { - throw "VSTestConsoleVersion for $propertyName is empty." - } + # Build with multiple versions of MSTest. The projects are directly in the root. + # The folder structure in VS is not echoed in the TestAssets directory. + $projects = @( + "$env:TP_ROOT_DIR\test\TestAssets\MSTestProject1\MSTestProject1.csproj" + "$env:TP_ROOT_DIR\test\TestAssets\MSTestProject2\MSTestProject2.csproj" + # Don't use this one, it does not use the variables for mstest and test sdk. + # "$env:TP_ROOT_DIR\test\TestAssets\SimpleTestProject2\SimpleTestProject2.csproj" + ) + + $msTestVersionProperties = @( + "MSTestFrameworkLatestPreviewVersion" + "MSTestFrameworkLatestStableVersion" + "MSTestFrameworkRecentStableVersion" + "MSTestFrameworkMostDownloadedVersion" + "MSTestFrameworkPreviousStableVersion" + "MSTestFrameworkLegacyStableVersion" + ) + + # We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. + foreach ($sdkPropertyName in $vstestConsoleVersionProperties) { + if ("VSTestConsoleLatestVersion" -eq $sdkPropertyName) { + # NETTestSdkVersion has the version of the locally built package. + $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup."NETTestSdkVersion" + } + else { + $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup.$sdkPropertyName + } + + if (-not $netTestSdkVersion) { + throw "NetTestSdkVersion for $sdkPropertyName is empty." + } + + $cacheId[$sdkPropertyName] = $netTestSdkVersion + } - # We don't use the results of this build anywhere, we just use them to restore the packages to nuget cache - # because using nuget.exe install errors out in various weird ways. - Invoke-Exe $dotnetExe -Arguments "build $env:TP_ROOT_DIR\test\TestAssets\Tools\Tools.csproj --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -p:NETTestSdkVersion=$vsTestConsoleVersion" + foreach ($propertyName in $msTestVersionProperties) { + $mstestVersion = $dependenciesXml.Project.PropertyGroup.$propertyName + + if (-not $mstestVersion) { + throw "MSTestVersion for $propertyName is empty." } - # Build with multiple versions of MSTest. The projects are directly in the root. - # The folder structure in VS is not echoed in the TestAssets directory. - $projects = @( - "$env:TP_ROOT_DIR\test\TestAssets\MSTestProject1\MSTestProject1.csproj" - "$env:TP_ROOT_DIR\test\TestAssets\MSTestProject2\MSTestProject2.csproj" - # Don't use this one, it does not use the variables for mstest and test sdk. - # "$env:TP_ROOT_DIR\test\TestAssets\SimpleTestProject2\SimpleTestProject2.csproj" - ) - - $msTestVersionProperties = @( - "MSTestFrameworkLatestPreviewVersion" - "MSTestFrameworkLatestStableVersion" - "MSTestFrameworkRecentStableVersion" - "MSTestFrameworkMostDownloadedVersion" - "MSTestFrameworkPreviousStableVersion" - "MSTestFrameworkLegacyStableVersion" - ) + $cacheId[$propertyName] = $mstestVersion + } + + $cacheId["projects"] = $projects + + $cacheIdText = $cacheId | ConvertTo-Json + + $currentCacheId = if (Test-Path "$generated/checksum.json") { Get-Content "$generated/checksum.json" -Raw } + + if ($cacheIdText -eq $currentCacheId) { + if (Test-Path $generatedSln) { + Write-Log ".. .. Build: Source: $generatedSln, cache is up to date, just building the solution." + Invoke-Exe $dotnetExe -Arguments "build $generatedSln" + return + } + } + + if (Test-Path $generated) { + Remove-Item $generated -Recurse -Force + } + + New-Item -ItemType Directory -Force -Path $generated | Out-Null + + Write-Log ".. .. Generate: Source: $generatedSln" + $nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe" + $nugetConfigSource = Join-Path $TPB_TestAssets "NuGet.config" + $nugetConfig = Join-Path $generated "NuGet.config" + + Invoke-Exe $dotnetExe -Arguments "new sln --name CompatibilityTestAssets --output ""$generated""" + + Write-Log ".. .. Build: Source: $generatedSln" + try { + $projectsToAdd = @() + $nugetConfigSource = Join-Path $TPB_TestAssets "NuGet.config" + $nugetConfig = Join-Path $generated "NuGet.config" + + Copy-Item -Path $nugetConfigSource -Destination $nugetConfig + + Write-Log ".. .. Build: Source: $generatedSln -- add NuGet source" + Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources add -Name ""locally-built-testplatform-packages"" -Source $env:TP_TESTARTIFACTS\packages\ -ConfigFile ""$nugetConfig""" foreach ($project in $projects) { + $projectName = Split-Path -Path $project -Leaf + $projectDir = Split-Path -Path $project -Parent + $projectItems = Get-ChildItem $projectDir | Where-Object { $_.Name -notin "bin", "obj" } | ForEach-Object { Get-ChildItem $_ -Recurse -File } + # We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. foreach ($sdkPropertyName in $vstestConsoleVersionProperties) { if ("VSTestConsoleLatestVersion" -eq $sdkPropertyName) { @@ -247,11 +318,43 @@ function Invoke-TestAssetsBuild { $dirMSTestVersion = $mstestVersion -replace "\[|\]" $dirMSTestPropertyName = $propertyName -replace "Framework" -replace "Version" - Invoke-Exe $dotnetExe -Arguments "build $project --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -p:MSTestFrameworkVersion=$mstestVersion -p:MSTestAdapterVersion=$mstestVersion -p:NETTestSdkVersion=$netTestSdkVersion -p:BaseOutputPath=""bin\$dirNetTestSdkPropertyName-$dirNetTestSdkVersion\$dirMSTestPropertyName-$dirMSTestVersion\\"" -bl:""$env:TP_OUT_DIR\log\$Configuration\perm.binlog""" + + # Do not make this a folder structure, it will break the relative reference to scripts\build\TestAssets.props that we have in the project, + # because the relative path will be different. + $compatibilityProjectDir = "$generated/$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion--$projectName/" + if (Test-path $compatibilityProjectDir) { + $a = 10 + } + New-Item -ItemType Directory -Path $compatibilityProjectDir | Out-Null + $compatibilityProjectDir = Resolve-Path $compatibilityProjectDir + foreach ($projectItem in $projectItems) { + $relativePath = ($projectItem.FullName -replace [regex]::Escape($projectDir)).TrimStart("\") + $fullPath = Join-Path $compatibilityProjectDir $relativePath + try { + Copy-Item -Path $projectItem.FullName -Destination $fullPath + } + catch { + $a = 10 + } + } + + $compatibilityCsproj = Get-ChildItem -Path $compatibilityProjectDir -Filter *.csproj + $csprojContent = (Get-Content $compatibilityCsproj -Encoding UTF8) ` + -replace "\$\(MSTestFrameworkVersion\)", $mstestVersion ` + -replace "\$\(MSTestAdapterVersion\)", $mstestVersion ` + -replace "\$\(NETTestSdkVersion\)", $netTestSdkVersion + $csprojContent | Set-Content -Encoding UTF8 -Path $compatibilityCsproj -Force + + $uniqueCsprojName = Join-Path $compatibilityProjectDir "$([IO.Path]::GetFileNameWithoutExtension($projectName))-$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion.csproj" + Rename-Item $compatibilityCsproj $uniqueCsprojName + $projectsToAdd += $uniqueCsprojName } } } + Invoke-Exe $dotnetExe -Arguments "sln $generatedSln add $projectsToAdd" + Invoke-Exe $dotnetExe -Arguments "build $generatedSln" + $cacheIdText | Set-Content "$generated/checksum.json" -NoNewline # end } finally { @@ -259,7 +362,7 @@ function Invoke-TestAssetsBuild { Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources remove -Name ""locally-built-testplatform-packages"" -ConfigFile ""$nugetConfig""" } Write-Log ".. .. Build: Complete." - Write-Log "Invoke-TestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}" + Write-Log "Invoke-CompatibilityTestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}" } function Copy-PackageIntoStaticDirectory { @@ -484,10 +587,10 @@ function Publish-Package { # Publish Microsoft.TestPlatform.AdapterUtilities Copy-Bulk -root (Join-Path $env:TP_ROOT_DIR "src\Microsoft.TestPlatform.AdapterUtilities\bin\$TPB_Configuration") ` -files @{ - "$TPB_TargetFramework462/any" = $net462PackageDir # net462 - $TPB_TargetFrameworkNS10 = $netstandard10PackageDir # netstandard1_0 - $TPB_TargetFrameworkNS20 = $netstandard20PackageDir # netstandard2_0 - $TPB_TargetFrameworkUap100 = $uap100PackageDir # uap10.0 + "$TPB_TargetFramework462/any" = $net462PackageDir # net462 + $TPB_TargetFrameworkNS10 = $netstandard10PackageDir # netstandard1_0 + $TPB_TargetFrameworkNS20 = $netstandard20PackageDir # netstandard2_0 + $TPB_TargetFrameworkUap100 = $uap100PackageDir # uap10.0 } ################################################################################ @@ -1281,6 +1384,7 @@ if ($Force -or $Steps -contains "Manifest") { if ($Force -or $Steps -contains "PrepareAcceptanceTests") { Publish-PatchedDotnet Invoke-TestAssetsBuild + Invoke-CompatibilityTestAssetsBuild Publish-Tests } diff --git a/test/CompatibilityTestAssets/NuGet.config b/test/CompatibilityTestAssets/NuGet.config new file mode 100644 index 0000000000..1b13787645 --- /dev/null +++ b/test/CompatibilityTestAssets/NuGet.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/GeneratedTestAssets/CompatibilityTestAssets.sln b/test/GeneratedTestAssets/CompatibilityTestAssets.sln new file mode 100644 index 0000000000..c3cb3c3a7f --- /dev/null +++ b/test/GeneratedTestAssets/CompatibilityTestAssets.sln @@ -0,0 +1,14 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj new file mode 100644 index 0000000000..1181d1b10f --- /dev/null +++ b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj @@ -0,0 +1,28 @@ + + + + + + netcoreapp2.1;$(TargetNetFxVersion) + netcoreapp3.1 + false + Preview + + + + + $(MSTestFrameworkVersion) + + + $(MSTestAdapterVersion) + + + $(NETTestSdkVersion) + + + + + + + + diff --git a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs new file mode 100644 index 0000000000..17c1760f18 --- /dev/null +++ b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace MSTestProject1; + +[TestClass] +public class UnitTest1 +{ + [TestMethod] + public void PassingTest() + { + Assert.AreEqual(2, 2); + } + + [TestMethod] + public void FailingTest() + { + Assert.AreEqual(2, 3); + } + + [Ignore] + [TestMethod] + public void SkippedTest() + { + } +} diff --git a/test/GeneratedTestAssets/NuGet.config b/test/GeneratedTestAssets/NuGet.config new file mode 100644 index 0000000000..96d708a7c3 --- /dev/null +++ b/test/GeneratedTestAssets/NuGet.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/test/TestAssets/NuGet.config b/test/TestAssets/NuGet.config index d4a9cb8272..96d708a7c3 100644 --- a/test/TestAssets/NuGet.config +++ b/test/TestAssets/NuGet.config @@ -3,20 +3,6 @@ - - - - - - - - - - - - - - diff --git a/test/TestAssets/TestAssets.sln b/test/TestAssets/TestAssets.sln index 8fae3a203e..84b8d6226a 100644 --- a/test/TestAssets/TestAssets.sln +++ b/test/TestAssets/TestAssets.sln @@ -120,8 +120,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTestProject1", "MSTestPro EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "basic", "basic", "{2633D125-64A7-456C-AD37-F8A6B56C2403}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools", "Tools\Tools.csproj", "{85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Perfy.TestAdapter", "performance\Perfy.TestAdapter\Perfy.TestAdapter.csproj", "{71BF7EC9-7BEE-4038-8F4E-87032FA4E995}" EndProject Global @@ -782,18 +780,6 @@ Global {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x64.Build.0 = Release|Any CPU {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x86.ActiveCfg = Release|Any CPU {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x86.Build.0 = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x64.ActiveCfg = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x64.Build.0 = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x86.ActiveCfg = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x86.Build.0 = Debug|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|Any CPU.Build.0 = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x64.ActiveCfg = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x64.Build.0 = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x86.ActiveCfg = Release|Any CPU - {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x86.Build.0 = Release|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|Any CPU.Build.0 = Debug|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/test/TestAssets/Tools/Program.cs b/test/TestAssets/Tools/Program.cs deleted file mode 100644 index 94783ab8a9..0000000000 --- a/test/TestAssets/Tools/Program.cs +++ /dev/null @@ -1,7 +0,0 @@ -// See https://aka.ms/new-console-template for more information -using System; - -// This project is used to restore TestPlatform and TestPlatform.CLI tools packages -// for testing with older versions. - -Console.WriteLine("Hello, World!"); diff --git a/test/TestAssets/Tools/Tools.csproj b/test/TestAssets/Tools/Tools.csproj deleted file mode 100644 index 5981f1c93c..0000000000 --- a/test/TestAssets/Tools/Tools.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - ..\..\..\ - true - true - - - - - - net5.0 - Exe - hanging_child - - - - - - - - - From 5183149234b9fec6bcfd8c92ce7fe8b4daad1c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 Jul 2022 13:34:34 +0200 Subject: [PATCH 2/8] Ignore generated sources --- .gitignore | 2 ++ .../CompatibilityTestAssets.sln | 14 ---------- .../MSTestProject1.csproj | 28 ------------------- .../UnitTest1.cs | 28 ------------------- test/GeneratedTestAssets/NuGet.config | 14 ---------- 5 files changed, 2 insertions(+), 84 deletions(-) delete mode 100644 test/GeneratedTestAssets/CompatibilityTestAssets.sln delete mode 100644 test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj delete mode 100644 test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs delete mode 100644 test/GeneratedTestAssets/NuGet.config diff --git a/.gitignore b/.gitignore index 0d22715429..0b3cb01773 100644 --- a/.gitignore +++ b/.gitignore @@ -113,6 +113,8 @@ ehthumbs.db *.zip /src/package/sign/sign.nuget.targets +test/GeneratedTestAssets/ + # =========================== # Localized resx files # =========================== diff --git a/test/GeneratedTestAssets/CompatibilityTestAssets.sln b/test/GeneratedTestAssets/CompatibilityTestAssets.sln deleted file mode 100644 index c3cb3c3a7f..0000000000 --- a/test/GeneratedTestAssets/CompatibilityTestAssets.sln +++ /dev/null @@ -1,14 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj deleted file mode 100644 index 1181d1b10f..0000000000 --- a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/MSTestProject1.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - netcoreapp2.1;$(TargetNetFxVersion) - netcoreapp3.1 - false - Preview - - - - - $(MSTestFrameworkVersion) - - - $(MSTestAdapterVersion) - - - $(NETTestSdkVersion) - - - - - - - - diff --git a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs b/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs deleted file mode 100644 index 17c1760f18..0000000000 --- a/test/GeneratedTestAssets/NETTestSdkLatest-17.4.0-dev--MSTestLatestPreview-2.3.0-preview-20220613-02--MSTestProject1.csproj/UnitTest1.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace MSTestProject1; - -[TestClass] -public class UnitTest1 -{ - [TestMethod] - public void PassingTest() - { - Assert.AreEqual(2, 2); - } - - [TestMethod] - public void FailingTest() - { - Assert.AreEqual(2, 3); - } - - [Ignore] - [TestMethod] - public void SkippedTest() - { - } -} diff --git a/test/GeneratedTestAssets/NuGet.config b/test/GeneratedTestAssets/NuGet.config deleted file mode 100644 index 96d708a7c3..0000000000 --- a/test/GeneratedTestAssets/NuGet.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - From 694b7ecd7c4434304acccb025621b6b07a22f6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 Jul 2022 15:47:22 +0200 Subject: [PATCH 3/8] Fix build --- scripts/build.ps1 | 105 ++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 19c9e333a4..090e9de3ef 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -287,11 +287,14 @@ function Invoke-CompatibilityTestAssetsBuild { Write-Log ".. .. Build: Source: $generatedSln -- add NuGet source" Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources add -Name ""locally-built-testplatform-packages"" -Source $env:TP_TESTARTIFACTS\packages\ -ConfigFile ""$nugetConfig""" + Write-Log ".. .. Build: Source: $generatedSln -- generate solution" foreach ($project in $projects) { $projectName = Split-Path -Path $project -Leaf - $projectDir = Split-Path -Path $project -Parent - $projectItems = Get-ChildItem $projectDir | Where-Object { $_.Name -notin "bin", "obj" } | ForEach-Object { Get-ChildItem $_ -Recurse -File } - + $projectBaseName = [IO.Path]::GetFileNameWithoutExtension($projectName) + $projectDir = Split-Path -Path $project + $projectItems = Get-ChildItem $projectDir | Where-Object { $_.Name -notin "bin", "obj" } | ForEach-Object { if ($_.PsIsContainer) { Get-ChildItem $_ -Recurse -File } else { $_ } } + + Write-Log ".. .. .. Project $project has $($projectItems.Count) project items." # We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. foreach ($sdkPropertyName in $vstestConsoleVersionProperties) { if ("VSTestConsoleLatestVersion" -eq $sdkPropertyName) { @@ -321,9 +324,10 @@ function Invoke-CompatibilityTestAssetsBuild { # Do not make this a folder structure, it will break the relative reference to scripts\build\TestAssets.props that we have in the project, # because the relative path will be different. - $compatibilityProjectDir = "$generated/$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion--$projectName/" + $compatibilityProjectDir = "$generated/$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion--$projectBaseName" + if (Test-path $compatibilityProjectDir) { - $a = 10 + throw "Path '$compatibilityProjectDir' does not exist" } New-Item -ItemType Directory -Path $compatibilityProjectDir | Out-Null $compatibilityProjectDir = Resolve-Path $compatibilityProjectDir @@ -331,14 +335,20 @@ function Invoke-CompatibilityTestAssetsBuild { $relativePath = ($projectItem.FullName -replace [regex]::Escape($projectDir)).TrimStart("\") $fullPath = Join-Path $compatibilityProjectDir $relativePath try { - Copy-Item -Path $projectItem.FullName -Destination $fullPath + Copy-Item -Path $projectItem.FullName -Destination $fullPath -Verbose } - catch { - $a = 10 + catch { + # can throw on wrong path, this makes the error more verbose + throw "$_, Source: '$($projectItem.FullName)', Destination: '$fullPath'" } } - $compatibilityCsproj = Get-ChildItem -Path $compatibilityProjectDir -Filter *.csproj + $compatibilityCsproj = Get-ChildItem -Path $compatibilityProjectDir -Filter *.csproj + if (-not $compatibilityCsproj) { + throw "No .csproj files found in directory $compatibilityProjectDir." + } + + $compatibilityCsproj = $compatibilityCsproj.FullName $csprojContent = (Get-Content $compatibilityCsproj -Encoding UTF8) ` -replace "\$\(MSTestFrameworkVersion\)", $mstestVersion ` -replace "\$\(MSTestAdapterVersion\)", $mstestVersion ` @@ -348,10 +358,13 @@ function Invoke-CompatibilityTestAssetsBuild { $uniqueCsprojName = Join-Path $compatibilityProjectDir "$([IO.Path]::GetFileNameWithoutExtension($projectName))-$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion.csproj" Rename-Item $compatibilityCsproj $uniqueCsprojName $projectsToAdd += $uniqueCsprojName + + Write-Log ".. .. .. Generated: $uniqueCsprojName" } } } + Write-Log ".. .. .. Building: generatedSln" Invoke-Exe $dotnetExe -Arguments "sln $generatedSln add $projectsToAdd" Invoke-Exe $dotnetExe -Arguments "build $generatedSln" $cacheIdText | Set-Content "$generated/checksum.json" -NoNewline @@ -1345,45 +1358,45 @@ Get-ChildItem env: | Where-Object -FilterScript { $_.Name.StartsWith("TP_") } | Write-Log "Test platform build variables: " Get-Variable | Where-Object -FilterScript { $_.Name.StartsWith("TPB_") } | Format-Table -if ($Force -or $Steps -contains "InstallDotnet") { - Install-DotNetCli -} - -if ($Force -or $Steps -contains "Restore") { - Clear-Package - Restore-Package -} - -if ($Force -or $Steps -contains "UpdateLocalization") { - Update-LocalizedResources -} - -if ($Force -or $Steps -contains "Build") { - Invoke-Build -} - -if ($Force -or $Steps -contains "Publish") { - Publish-Package - Publish-VsixPackage -} - -if ($Force -or $Steps -contains "Pack") { - Create-VsixPackage - Create-NugetPackages -} - -if ($Force -or $Steps -contains "Manifest") { - Generate-Manifest -PackageFolder $TPB_PackageOutDir - if (Test-Path $TPB_SourceBuildPackageOutDir) - { - Generate-Manifest -PackageFolder $TPB_SourceBuildPackageOutDir - } - Copy-PackageIntoStaticDirectory -} +# if ($Force -or $Steps -contains "InstallDotnet") { +# Install-DotNetCli +# } + +# if ($Force -or $Steps -contains "Restore") { +# Clear-Package +# Restore-Package +# } + +# if ($Force -or $Steps -contains "UpdateLocalization") { +# Update-LocalizedResources +# } + +# if ($Force -or $Steps -contains "Build") { +# Invoke-Build +# } + +# if ($Force -or $Steps -contains "Publish") { +# Publish-Package +# Publish-VsixPackage +# } + +# if ($Force -or $Steps -contains "Pack") { +# Create-VsixPackage +# Create-NugetPackages +# } + +# if ($Force -or $Steps -contains "Manifest") { +# Generate-Manifest -PackageFolder $TPB_PackageOutDir +# if (Test-Path $TPB_SourceBuildPackageOutDir) +# { +# Generate-Manifest -PackageFolder $TPB_SourceBuildPackageOutDir +# } +# Copy-PackageIntoStaticDirectory +# } if ($Force -or $Steps -contains "PrepareAcceptanceTests") { - Publish-PatchedDotnet - Invoke-TestAssetsBuild + # Publish-PatchedDotnet + # Invoke-TestAssetsBuild Invoke-CompatibilityTestAssetsBuild Publish-Tests } From e676f0b3496fb811ce97e7fa4462a94b46b3837b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 Jul 2022 16:00:19 +0200 Subject: [PATCH 4/8] Build --- scripts/build.ps1 | 74 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 090e9de3ef..65a91e7f44 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -1358,45 +1358,45 @@ Get-ChildItem env: | Where-Object -FilterScript { $_.Name.StartsWith("TP_") } | Write-Log "Test platform build variables: " Get-Variable | Where-Object -FilterScript { $_.Name.StartsWith("TPB_") } | Format-Table -# if ($Force -or $Steps -contains "InstallDotnet") { -# Install-DotNetCli -# } - -# if ($Force -or $Steps -contains "Restore") { -# Clear-Package -# Restore-Package -# } - -# if ($Force -or $Steps -contains "UpdateLocalization") { -# Update-LocalizedResources -# } - -# if ($Force -or $Steps -contains "Build") { -# Invoke-Build -# } - -# if ($Force -or $Steps -contains "Publish") { -# Publish-Package -# Publish-VsixPackage -# } - -# if ($Force -or $Steps -contains "Pack") { -# Create-VsixPackage -# Create-NugetPackages -# } - -# if ($Force -or $Steps -contains "Manifest") { -# Generate-Manifest -PackageFolder $TPB_PackageOutDir -# if (Test-Path $TPB_SourceBuildPackageOutDir) -# { -# Generate-Manifest -PackageFolder $TPB_SourceBuildPackageOutDir -# } -# Copy-PackageIntoStaticDirectory -# } +if ($Force -or $Steps -contains "InstallDotnet") { + Install-DotNetCli +} + +if ($Force -or $Steps -contains "Restore") { + Clear-Package + Restore-Package +} + +if ($Force -or $Steps -contains "UpdateLocalization") { + Update-LocalizedResources +} + +if ($Force -or $Steps -contains "Build") { + Invoke-Build +} + +if ($Force -or $Steps -contains "Publish") { + Publish-Package + Publish-VsixPackage +} + +if ($Force -or $Steps -contains "Pack") { + Create-VsixPackage + Create-NugetPackages +} + +if ($Force -or $Steps -contains "Manifest") { + Generate-Manifest -PackageFolder $TPB_PackageOutDir + if (Test-Path $TPB_SourceBuildPackageOutDir) + { + Generate-Manifest -PackageFolder $TPB_SourceBuildPackageOutDir + } + Copy-PackageIntoStaticDirectory +} if ($Force -or $Steps -contains "PrepareAcceptanceTests") { - # Publish-PatchedDotnet - # Invoke-TestAssetsBuild + Publish-PatchedDotnet + Invoke-TestAssetsBuild Invoke-CompatibilityTestAssetsBuild Publish-Tests } From c1dac5b727d47bd0a20f11a861c39327db5c3121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 20 Jul 2022 19:03:02 +0200 Subject: [PATCH 5/8] Short id in build --- scripts/build.ps1 | 18 ++++++++++----- test/CompatibilityTestAssets/NuGet.config | 16 ------------- .../AcceptanceTestBase.cs | 2 +- .../Extension/CompatibilityRowsBuilder.cs | 18 ++++----------- .../DllInfo.cs | 11 --------- .../IntegrationTestEnvironment.cs | 8 +++---- test/TestAssets/TestAssets.sln | 14 +++++++++++ test/TestAssets/Tools/Program.cs | 7 ++++++ test/TestAssets/Tools/Tools.csproj | 23 +++++++++++++++++++ 9 files changed, 65 insertions(+), 52 deletions(-) delete mode 100644 test/CompatibilityTestAssets/NuGet.config create mode 100644 test/TestAssets/Tools/Program.cs create mode 100644 test/TestAssets/Tools/Tools.csproj diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 65a91e7f44..ba2f565fb3 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -78,8 +78,6 @@ Write-Verbose "Setup build configuration." $TPB_TestAssets = Join-Path $env:TP_ROOT_DIR "test\TestAssets\" $TPB_Solution = Join-Path $env:TP_ROOT_DIR "TestPlatform.sln" $TPB_TestAssets_Solution = Join-Path $TPB_TestAssets "TestAssets.sln" -$TPB_CompatibilityTestAssets = Join-Path $env:TP_ROOT_DIR "test\CompatibilityTestAssets\" -$TPB_CompatibilityTestAssets_Solution = Join-Path $TPB_CompatibilityTestAssets "TestAssets.sln" $TPB_TestAssets_CILAssets = Join-Path $TPB_TestAssets "CILProject\CILProject.proj" $TPB_TargetFramework462 = "net462" $TPB_TargetFramework472 = "net472" @@ -237,6 +235,10 @@ function Invoke-CompatibilityTestAssetsBuild { } $cacheId[$sdkPropertyName] = $netTestSdkVersion + + # We don't use the results of this build anywhere, we just use them to restore the packages to nuget cache + # because using nuget.exe install errors out in various weird ways. + Invoke-Exe $dotnetExe -Arguments "build $env:TP_ROOT_DIR\test\TestAssets\Tools\Tools.csproj --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -p:NETTestSdkVersion=$netTestSdkVersion" } foreach ($propertyName in $msTestVersionProperties) { @@ -258,7 +260,7 @@ function Invoke-CompatibilityTestAssetsBuild { if ($cacheIdText -eq $currentCacheId) { if (Test-Path $generatedSln) { Write-Log ".. .. Build: Source: $generatedSln, cache is up to date, just building the solution." - Invoke-Exe $dotnetExe -Arguments "build $generatedSln" + Invoke-Exe $dotnetExe -Arguments "build $generatedSln --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild" return } } @@ -324,7 +326,11 @@ function Invoke-CompatibilityTestAssetsBuild { # Do not make this a folder structure, it will break the relative reference to scripts\build\TestAssets.props that we have in the project, # because the relative path will be different. - $compatibilityProjectDir = "$generated/$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion--$projectBaseName" + # + # It would be nice to use fully descriptive name but it is too long, hash the versions instead. + # $compatibilityProjectDir = "$generated/$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion" + $projectShortName = "$projectBaseName--"+([string]::Format("{0:X}", "$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion".GetHashCode())) + $compatibilityProjectDir = "$generated/$projectShortName" if (Test-path $compatibilityProjectDir) { throw "Path '$compatibilityProjectDir' does not exist" @@ -355,7 +361,7 @@ function Invoke-CompatibilityTestAssetsBuild { -replace "\$\(NETTestSdkVersion\)", $netTestSdkVersion $csprojContent | Set-Content -Encoding UTF8 -Path $compatibilityCsproj -Force - $uniqueCsprojName = Join-Path $compatibilityProjectDir "$([IO.Path]::GetFileNameWithoutExtension($projectName))-$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion.csproj" + $uniqueCsprojName = Join-Path $compatibilityProjectDir "$projectShortName.csproj" Rename-Item $compatibilityCsproj $uniqueCsprojName $projectsToAdd += $uniqueCsprojName @@ -366,7 +372,7 @@ function Invoke-CompatibilityTestAssetsBuild { Write-Log ".. .. .. Building: generatedSln" Invoke-Exe $dotnetExe -Arguments "sln $generatedSln add $projectsToAdd" - Invoke-Exe $dotnetExe -Arguments "build $generatedSln" + Invoke-Exe $dotnetExe -Arguments "build $generatedSln --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild" $cacheIdText | Set-Content "$generated/checksum.json" -NoNewline # end } diff --git a/test/CompatibilityTestAssets/NuGet.config b/test/CompatibilityTestAssets/NuGet.config deleted file mode 100644 index 1b13787645..0000000000 --- a/test/CompatibilityTestAssets/NuGet.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs b/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs index 8bae251d1e..75fe0f5b0a 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs @@ -65,7 +65,7 @@ protected static void SetTestEnvironment(IntegrationTestEnvironment testEnvironm { testEnvironment.VSTestConsoleInfo = runnerInfo.VSTestConsoleInfo; // The order here matters, it changes how the resulting path is built when we resolve test dlls and other assets. - testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).Select(x => x!).ToList(); + testEnvironment.DllInfos = new[] { runnerInfo.TestHostInfo, runnerInfo.AdapterInfo }.Where(d => d != null).Select(x => x!).ToList(); testEnvironment.DebugInfo = runnerInfo.DebugInfo; testEnvironment.RunnerFramework = runnerInfo.RunnerFramework!; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/CompatibilityRowsBuilder.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/CompatibilityRowsBuilder.cs index 9a0ac43d3e..dfa0b5d58c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/CompatibilityRowsBuilder.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/CompatibilityRowsBuilder.cs @@ -287,13 +287,6 @@ private void AddRow(List dataRows, string batch, RunnerInfo runnerInfo = GetRunnerInfo(batch, runnerFramework, hostFramework, inIsolation); runnerInfo.DebugInfo = GetDebugInfo(); runnerInfo.VSTestConsoleInfo = GetVSTestConsoleInfo(runnerVersion, runnerInfo); - - // The order in which we add them matters. We end up both modifying the same path - // and adding to it. So the first one added will be later in the path. E.g.: - // Adding testSdk first: - // C:\p\vstest\test\TestAssets\MSTestProject1\bin\MSTestLatestPreview-2.2.9-preview-20220210-07\NETTestSdkLatest-17.2.0-dev\Debug\net462\MSTestProject1.dll - // versus adding testSdk second: - // C:\p\vstest\test\TestAssets\MSTestProject1\bin\NETTestSdkLatest-17.2.0-dev\MSTestLatestPreview-2.2.9-preview-20220210-07\Debug\net462\MSTestProject1.dll runnerInfo.TestHostInfo = GetNetTestSdkInfo(hostVersion); runnerInfo.AdapterInfo = GetMSTestInfo(adapterVersion); dataRows.Add(runnerInfo); @@ -329,8 +322,7 @@ private static DllInfo GetMSTestInfo(string msTestVersion) // This way it throws in the body of the test which has better error reporting than throwing in the data source. XmlNode? node = depsXml.DocumentElement?.SelectSingleNode($"PropertyGroup/MSTestFramework{msTestVersion}Version"); var version = node?.InnerText.Replace("[", "").Replace("]", ""); - var slash = Path.DirectorySeparatorChar; - var versionSpecificBinPath = $"{slash}bin{slash}MSTest{msTestVersion}-{version}{slash}"; + var versionSpecificPath = $"MSTest{msTestVersion}-{version}"; return new DllInfo { @@ -338,7 +330,7 @@ private static DllInfo GetMSTestInfo(string msTestVersion) PropertyName = "MSTest", VersionType = msTestVersion, Version = version, - Path = versionSpecificBinPath, + Path = versionSpecificPath, }; } @@ -391,7 +383,6 @@ private static NetTestSdkInfo GetNetTestSdkInfo(string testhostVersionType) // When version is Latest, we built it locally, but it gets restored into our nuget cache on build // same as other versions, we just need to grab the version from a different property. - var propertyName = testhostVersionType == AcceptanceTestBase.LATEST ? "NETTestSdkVersion" : $"VSTestConsole{testhostVersionType}Version"; @@ -402,14 +393,13 @@ private static NetTestSdkInfo GetNetTestSdkInfo(string testhostVersionType) // We use the VSTestConsole properties to figure out testhost version, for now. XmlNode? node = depsXml.DocumentElement?.SelectSingleNode($"PropertyGroup/{propertyName}"); var version = node?.InnerText.Replace("[", "").Replace("]", ""); - var slash = Path.DirectorySeparatorChar; - var versionSpecificBinPath = $"{slash}bin{slash}NETTestSdk{testhostVersionType}-{version}{slash}"; + var versionSpecificPath = $"NETTestSdk{testhostVersionType}-{version}"; return new NetTestSdkInfo { VersionType = testhostVersionType, Version = version, - Path = versionSpecificBinPath + Path = versionSpecificPath }; } diff --git a/test/Microsoft.TestPlatform.TestUtilities/DllInfo.cs b/test/Microsoft.TestPlatform.TestUtilities/DllInfo.cs index b5d0590b65..f840e9b983 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/DllInfo.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/DllInfo.cs @@ -19,15 +19,4 @@ public class DllInfo public string? Path { get; set; } public override string ToString() => $" {Name} = {Version} [{VersionType}]"; - - public string UpdatePath(string path) - { - // Version is not directly used, below, but if it is not populated the path will be incorrect. - // We don't want to throw when creating SourcePathInfo because that is happening too early, and has worse error reporting. - if (Version == null) - throw new InvalidOperationException($"Version was not correctly populated from TestPlatform.Dependencies.props, review that there is entry for {PropertyName}{VersionType}Version."); - - // TODO: replacing in the result string is lame, but I am not going to fight 20 GetAssetFullPath method overloads right now - return path.Replace($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}", Path); - } } diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index 886ba29d34..2a670047f6 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Linq; using System.Xml; using Microsoft.VisualStudio.TestPlatform.Common; @@ -216,10 +217,9 @@ public string GetTestAsset(string assetName, string targetFramework) // Update the path to be taken from the compatibility matrix instead of from the root folder. if (DllInfos.Count > 0) { - foreach (var dllInfo in DllInfos) - { - assetPath = dllInfo.UpdatePath(assetPath); - } + // The path is really ugly: S:\p\vstest3\test\GeneratedTestAssets\NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0--MSTestProject2\bin\Debug\net462\MSTestProject2-NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0.dll + var versions = string.Join("--", DllInfos.Select(d => d.Path)); + assetPath = Path.Combine(TestAssetsPath, "..", "GeneratedTestAssets", $"{simpleAssetName}--{versions}", "bin", BuildConfiguration, targetFramework, $"{simpleAssetName}--{versions}.dll"); } Assert.IsTrue(File.Exists(assetPath), "GetTestAsset: Path not found: \"{0}\". Most likely you need to build using build.cmd -s PrepareAcceptanceTests.", assetPath); diff --git a/test/TestAssets/TestAssets.sln b/test/TestAssets/TestAssets.sln index 84b8d6226a..8fae3a203e 100644 --- a/test/TestAssets/TestAssets.sln +++ b/test/TestAssets/TestAssets.sln @@ -120,6 +120,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTestProject1", "MSTestPro EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "basic", "basic", "{2633D125-64A7-456C-AD37-F8A6B56C2403}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools", "Tools\Tools.csproj", "{85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Perfy.TestAdapter", "performance\Perfy.TestAdapter\Perfy.TestAdapter.csproj", "{71BF7EC9-7BEE-4038-8F4E-87032FA4E995}" EndProject Global @@ -780,6 +782,18 @@ Global {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x64.Build.0 = Release|Any CPU {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x86.ActiveCfg = Release|Any CPU {E166D337-4033-4209-863F-8F77675EAEE8}.Release|x86.Build.0 = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x64.ActiveCfg = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x64.Build.0 = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x86.ActiveCfg = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Debug|x86.Build.0 = Debug|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|Any CPU.Build.0 = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x64.ActiveCfg = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x64.Build.0 = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x86.ActiveCfg = Release|Any CPU + {85F9F2A8-D2A5-4EA1-8BE0-06CCE141EC7A}.Release|x86.Build.0 = Release|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|Any CPU.Build.0 = Debug|Any CPU {71BF7EC9-7BEE-4038-8F4E-87032FA4E995}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/test/TestAssets/Tools/Program.cs b/test/TestAssets/Tools/Program.cs new file mode 100644 index 0000000000..94783ab8a9 --- /dev/null +++ b/test/TestAssets/Tools/Program.cs @@ -0,0 +1,7 @@ +// See https://aka.ms/new-console-template for more information +using System; + +// This project is used to restore TestPlatform and TestPlatform.CLI tools packages +// for testing with older versions. + +Console.WriteLine("Hello, World!"); diff --git a/test/TestAssets/Tools/Tools.csproj b/test/TestAssets/Tools/Tools.csproj new file mode 100644 index 0000000000..5981f1c93c --- /dev/null +++ b/test/TestAssets/Tools/Tools.csproj @@ -0,0 +1,23 @@ + + + + ..\..\..\ + true + true + + + + + + net5.0 + Exe + hanging_child + + + + + + + + + From daef9bf3dc1b84b1f4e63b17d8a3533a65255938 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Thu, 21 Jul 2022 17:54:23 +0200 Subject: [PATCH 6/8] versions --- scripts/build.ps1 | 2 +- .../IntegrationTestEnvironment.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index ba2f565fb3..104593fe31 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -329,7 +329,7 @@ function Invoke-CompatibilityTestAssetsBuild { # # It would be nice to use fully descriptive name but it is too long, hash the versions instead. # $compatibilityProjectDir = "$generated/$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion" - $projectShortName = "$projectBaseName--"+([string]::Format("{0:X}", "$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion".GetHashCode())) + $projectShortName = [string]::Format("{0:X}", "$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion".GetHashCode()) $compatibilityProjectDir = "$generated/$projectShortName" if (Test-path $compatibilityProjectDir) { diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index 2a670047f6..1afe0673c1 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -218,8 +218,10 @@ public string GetTestAsset(string assetName, string targetFramework) if (DllInfos.Count > 0) { // The path is really ugly: S:\p\vstest3\test\GeneratedTestAssets\NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0--MSTestProject2\bin\Debug\net462\MSTestProject2-NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0.dll + // And we need to hash the versions in it to get shorter path as well. var versions = string.Join("--", DllInfos.Select(d => d.Path)); - assetPath = Path.Combine(TestAssetsPath, "..", "GeneratedTestAssets", $"{simpleAssetName}--{versions}", "bin", BuildConfiguration, targetFramework, $"{simpleAssetName}--{versions}.dll"); + var versionsHash = $"{versions.GetHashCode():X}"; + assetPath = Path.Combine(TestAssetsPath, "..", "GeneratedTestAssets", $"{simpleAssetName}--{versionsHash}", "bin", BuildConfiguration, targetFramework, $"{simpleAssetName}--{versionsHash}.dll"); } Assert.IsTrue(File.Exists(assetPath), "GetTestAsset: Path not found: \"{0}\". Most likely you need to build using build.cmd -s PrepareAcceptanceTests.", assetPath); From e21367737ed4721c9c746767c91dd83ef874900c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 22 Jul 2022 10:20:03 +0200 Subject: [PATCH 7/8] Head --- scripts/build.ps1 | 187 +++++++++--------- scripts/common.lib.ps1 | 29 +++ .../IntegrationTestEnvironment.cs | 16 +- 3 files changed, 140 insertions(+), 92 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 104593fe31..bbd9f111a3 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -257,128 +257,133 @@ function Invoke-CompatibilityTestAssetsBuild { $currentCacheId = if (Test-Path "$generated/checksum.json") { Get-Content "$generated/checksum.json" -Raw } + $rebuild = $true if ($cacheIdText -eq $currentCacheId) { if (Test-Path $generatedSln) { Write-Log ".. .. Build: Source: $generatedSln, cache is up to date, just building the solution." Invoke-Exe $dotnetExe -Arguments "build $generatedSln --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild" - return + $rebuild = $false } } - if (Test-Path $generated) { - Remove-Item $generated -Recurse -Force - } - - New-Item -ItemType Directory -Force -Path $generated | Out-Null - - Write-Log ".. .. Generate: Source: $generatedSln" - $nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe" - $nugetConfigSource = Join-Path $TPB_TestAssets "NuGet.config" - $nugetConfig = Join-Path $generated "NuGet.config" + if ($rebuild) { + if (Test-Path $generated) { + Remove-Item $generated -Recurse -Force + } - Invoke-Exe $dotnetExe -Arguments "new sln --name CompatibilityTestAssets --output ""$generated""" + New-Item -ItemType Directory -Force -Path $generated | Out-Null - Write-Log ".. .. Build: Source: $generatedSln" - try { - $projectsToAdd = @() + Write-Log ".. .. Generate: Source: $generatedSln" + $nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe" $nugetConfigSource = Join-Path $TPB_TestAssets "NuGet.config" $nugetConfig = Join-Path $generated "NuGet.config" - Copy-Item -Path $nugetConfigSource -Destination $nugetConfig + Invoke-Exe $dotnetExe -Arguments "new sln --name CompatibilityTestAssets --output ""$generated""" - Write-Log ".. .. Build: Source: $generatedSln -- add NuGet source" - Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources add -Name ""locally-built-testplatform-packages"" -Source $env:TP_TESTARTIFACTS\packages\ -ConfigFile ""$nugetConfig""" + Write-Log ".. .. Build: Source: $generatedSln" + try { + $projectsToAdd = @() + $nugetConfigSource = Join-Path $TPB_TestAssets "NuGet.config" + $nugetConfig = Join-Path $generated "NuGet.config" - Write-Log ".. .. Build: Source: $generatedSln -- generate solution" - foreach ($project in $projects) { - $projectName = Split-Path -Path $project -Leaf - $projectBaseName = [IO.Path]::GetFileNameWithoutExtension($projectName) - $projectDir = Split-Path -Path $project - $projectItems = Get-ChildItem $projectDir | Where-Object { $_.Name -notin "bin", "obj" } | ForEach-Object { if ($_.PsIsContainer) { Get-ChildItem $_ -Recurse -File } else { $_ } } - - Write-Log ".. .. .. Project $project has $($projectItems.Count) project items." - # We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. - foreach ($sdkPropertyName in $vstestConsoleVersionProperties) { - if ("VSTestConsoleLatestVersion" -eq $sdkPropertyName) { - # NETTestSdkVersion has the version of the locally built package. - $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup."NETTestSdkVersion" - } - else { - $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup.$sdkPropertyName - } + Copy-Item -Path $nugetConfigSource -Destination $nugetConfig - if (-not $netTestSdkVersion) { - throw "NetTestSdkVersion for $sdkPropertyName is empty." - } + Write-Log ".. .. Build: Source: $generatedSln -- add NuGet source" + Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources add -Name ""locally-built-testplatform-packages"" -Source $env:TP_TESTARTIFACTS\packages\ -ConfigFile ""$nugetConfig""" - $dirNetTestSdkVersion = $netTestSdkVersion -replace "\[|\]" - $dirNetTestSdkPropertyName = $sdkPropertyName -replace "Framework" -replace "Version" -replace "VSTestConsole", "NETTestSdk" + Write-Log ".. .. Build: Source: $generatedSln -- generate solution" + foreach ($project in $projects) { + $projectName = Split-Path -Path $project -Leaf + $projectBaseName = [IO.Path]::GetFileNameWithoutExtension($projectName) + $projectDir = Split-Path -Path $project + $projectItems = Get-ChildItem $projectDir | Where-Object { $_.Name -notin "bin", "obj" } | ForEach-Object { if ($_.PsIsContainer) { Get-ChildItem $_ -Recurse -File } else { $_ } } - foreach ($propertyName in $msTestVersionProperties) { - $mstestVersion = $dependenciesXml.Project.PropertyGroup.$propertyName + Write-Log ".. .. .. Project $project has $($projectItems.Count) project items." + # We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. + foreach ($sdkPropertyName in $vstestConsoleVersionProperties) { + if ("VSTestConsoleLatestVersion" -eq $sdkPropertyName) { + # NETTestSdkVersion has the version of the locally built package. + $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup."NETTestSdkVersion" + } + else { + $netTestSdkVersion = $dependenciesXml.Project.PropertyGroup.$sdkPropertyName + } - if (-not $mstestVersion) { - throw "MSTestVersion for $propertyName is empty." + if (-not $netTestSdkVersion) { + throw "NetTestSdkVersion for $sdkPropertyName is empty." } - $dirMSTestVersion = $mstestVersion -replace "\[|\]" - $dirMSTestPropertyName = $propertyName -replace "Framework" -replace "Version" + $dirNetTestSdkVersion = $netTestSdkVersion -replace "\[|\]" + $dirNetTestSdkPropertyName = $sdkPropertyName -replace "Framework" -replace "Version" -replace "VSTestConsole", "NETTestSdk" - # Do not make this a folder structure, it will break the relative reference to scripts\build\TestAssets.props that we have in the project, - # because the relative path will be different. - # - # It would be nice to use fully descriptive name but it is too long, hash the versions instead. - # $compatibilityProjectDir = "$generated/$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion" - $projectShortName = [string]::Format("{0:X}", "$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion".GetHashCode()) - $compatibilityProjectDir = "$generated/$projectShortName" + foreach ($propertyName in $msTestVersionProperties) { + $mstestVersion = $dependenciesXml.Project.PropertyGroup.$propertyName - if (Test-path $compatibilityProjectDir) { - throw "Path '$compatibilityProjectDir' does not exist" - } - New-Item -ItemType Directory -Path $compatibilityProjectDir | Out-Null - $compatibilityProjectDir = Resolve-Path $compatibilityProjectDir - foreach ($projectItem in $projectItems) { - $relativePath = ($projectItem.FullName -replace [regex]::Escape($projectDir)).TrimStart("\") - $fullPath = Join-Path $compatibilityProjectDir $relativePath - try { - Copy-Item -Path $projectItem.FullName -Destination $fullPath -Verbose + if (-not $mstestVersion) { + throw "MSTestVersion for $propertyName is empty." } - catch { - # can throw on wrong path, this makes the error more verbose - throw "$_, Source: '$($projectItem.FullName)', Destination: '$fullPath'" + + $dirMSTestVersion = $mstestVersion -replace "\[|\]" + $dirMSTestPropertyName = $propertyName -replace "Framework" -replace "Version" + + # Do not make this a folder structure, it will break the relative reference to scripts\build\TestAssets.props that we have in the project, + # because the relative path will be different. + # + # It would be nice to use fully descriptive name but it is too long, hash the versions instead. + # $compatibilityProjectDir = "$generated/$projectBaseName--$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion" + $versions = "$dirNetTestSdkPropertyName-$dirNetTestSdkVersion--$dirMSTestPropertyName-$dirMSTestVersion" + $hash = Get-Hash $versions + Write-Host Hashed $versions to $hash + $projectShortName = "$projectBaseName--" + $hash + $compatibilityProjectDir = "$generated/$projectShortName" + + if (Test-path $compatibilityProjectDir) { + throw "Path '$compatibilityProjectDir' does not exist" + } + New-Item -ItemType Directory -Path $compatibilityProjectDir | Out-Null + $compatibilityProjectDir = Resolve-Path $compatibilityProjectDir + foreach ($projectItem in $projectItems) { + $relativePath = ($projectItem.FullName -replace [regex]::Escape($projectDir)).TrimStart("\") + $fullPath = Join-Path $compatibilityProjectDir $relativePath + try { + Copy-Item -Path $projectItem.FullName -Destination $fullPath -Verbose + } + catch { + # can throw on wrong path, this makes the error more verbose + throw "$_, Source: '$($projectItem.FullName)', Destination: '$fullPath'" + } } - } - $compatibilityCsproj = Get-ChildItem -Path $compatibilityProjectDir -Filter *.csproj - if (-not $compatibilityCsproj) { - throw "No .csproj files found in directory $compatibilityProjectDir." - } + $compatibilityCsproj = Get-ChildItem -Path $compatibilityProjectDir -Filter *.csproj + if (-not $compatibilityCsproj) { + throw "No .csproj files found in directory $compatibilityProjectDir." + } - $compatibilityCsproj = $compatibilityCsproj.FullName - $csprojContent = (Get-Content $compatibilityCsproj -Encoding UTF8) ` - -replace "\$\(MSTestFrameworkVersion\)", $mstestVersion ` - -replace "\$\(MSTestAdapterVersion\)", $mstestVersion ` - -replace "\$\(NETTestSdkVersion\)", $netTestSdkVersion - $csprojContent | Set-Content -Encoding UTF8 -Path $compatibilityCsproj -Force + $compatibilityCsproj = $compatibilityCsproj.FullName + $csprojContent = (Get-Content $compatibilityCsproj -Encoding UTF8) ` + -replace "\$\(MSTestFrameworkVersion\)", $mstestVersion ` + -replace "\$\(MSTestAdapterVersion\)", $mstestVersion ` + -replace "\$\(NETTestSdkVersion\)", $netTestSdkVersion + $csprojContent | Set-Content -Encoding UTF8 -Path $compatibilityCsproj -Force - $uniqueCsprojName = Join-Path $compatibilityProjectDir "$projectShortName.csproj" - Rename-Item $compatibilityCsproj $uniqueCsprojName - $projectsToAdd += $uniqueCsprojName + $uniqueCsprojName = Join-Path $compatibilityProjectDir "$projectShortName.csproj" + Rename-Item $compatibilityCsproj $uniqueCsprojName + $projectsToAdd += $uniqueCsprojName - Write-Log ".. .. .. Generated: $uniqueCsprojName" + Write-Log ".. .. .. Generated: $uniqueCsprojName" + } } } - } - Write-Log ".. .. .. Building: generatedSln" - Invoke-Exe $dotnetExe -Arguments "sln $generatedSln add $projectsToAdd" - Invoke-Exe $dotnetExe -Arguments "build $generatedSln --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild" - $cacheIdText | Set-Content "$generated/checksum.json" -NoNewline - # end - } - finally { - Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution -- remove NuGet source" - Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources remove -Name ""locally-built-testplatform-packages"" -ConfigFile ""$nugetConfig""" + Write-Log ".. .. .. Building: generatedSln" + Invoke-Exe $dotnetExe -Arguments "sln $generatedSln add $projectsToAdd" + Invoke-Exe $dotnetExe -Arguments "build $generatedSln --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild" + $cacheIdText | Set-Content "$generated/checksum.json" -NoNewline + } + finally { + Write-Log ".. .. Build: Source: $TPB_TestAssets_Solution -- remove NuGet source" + Invoke-Exe -IgnoreExitCode 1 $nugetExe -Arguments "sources remove -Name ""locally-built-testplatform-packages"" -ConfigFile ""$nugetConfig""" + } } Write-Log ".. .. Build: Complete." Write-Log "Invoke-CompatibilityTestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}" diff --git a/scripts/common.lib.ps1 b/scripts/common.lib.ps1 index 1e44242bd0..526939e0f7 100644 --- a/scripts/common.lib.ps1 +++ b/scripts/common.lib.ps1 @@ -388,3 +388,32 @@ function Start-InlineProcess { $process.Dispose() } } + +Add-Type -TypeDefinition @" + public static class Hash { + public static string GetHash(string value) + { + unchecked + { + ulong hash = 23; + foreach (char ch in value) + { + hash = hash * 31; + hash += ch; + } + + return string.Format("{0:X}", hash); + } + } + } +"@ + +function Get-Hash { + param ( + [Parameter(Mandatory)] + [string]$Value + ) + + # PowerShell does not have unchecked keyword, so we can't do unchecked math easily. + [Hash]::GetHash($Value) +} diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index 1afe0673c1..5a03b44d55 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -220,7 +220,7 @@ public string GetTestAsset(string assetName, string targetFramework) // The path is really ugly: S:\p\vstest3\test\GeneratedTestAssets\NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0--MSTestProject2\bin\Debug\net462\MSTestProject2-NETTestSdkLegacyStable-15.9.2--MSTestMostDownloaded-2.1.0.dll // And we need to hash the versions in it to get shorter path as well. var versions = string.Join("--", DllInfos.Select(d => d.Path)); - var versionsHash = $"{versions.GetHashCode():X}"; + var versionsHash = Hash(versions); assetPath = Path.Combine(TestAssetsPath, "..", "GeneratedTestAssets", $"{simpleAssetName}--{versionsHash}", "bin", BuildConfiguration, targetFramework, $"{simpleAssetName}--{versionsHash}.dll"); } @@ -229,6 +229,20 @@ public string GetTestAsset(string assetName, string targetFramework) // If you are thinking about wrapping the path in double quotes here, // then don't. File.Exist cannot handle quoted paths, and we use it in a lot of places. return assetPath; + + static string Hash(string value) + { + unchecked + { + long hash = 23; + foreach (char ch in value) + { + hash = hash * 31 + ch; + } + + return $"{hash:X}"; + } + } } /// From 1b215f5c61aca1cea848084a63bac34a618296d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 22 Jul 2022 11:48:09 +0200 Subject: [PATCH 8/8] Update scripts/build.ps1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Amaury Levé --- scripts/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index bbd9f111a3..5bf25ce54b 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -182,7 +182,7 @@ function Invoke-CompatibilityTestAssetsBuild { $generated = Join-Path (Split-Path -Path $TPB_TestAssets) -ChildPath "GeneratedTestAssets" $generatedSln = Join-Path $generated "CompatibilityTestAssets.sln" - # Figure out if the versions or the projects to build changed, and if they did not just + # Figure out if the versions or the projects to build changed, and if they did not # and the solution is already in place just build it. # Otherwise delete everything and regenerate and re-build. $dependenciesPath = "$env:TP_ROOT_DIR\scripts\build\TestPlatform.Dependencies.props"