Skip to content

ManagedName and backward compatibility fixes. #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2021
Merged
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
8 changes: 4 additions & 4 deletions Nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
<add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
<add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
<add key="dotnet5" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json" />
Expand All @@ -18,9 +18,9 @@
</activePackageSource>
<config>
<!-- This path is relative as a workaround to https://github.com./NuGet/Home/issues/2831 -->
<!-- <add key="globalPackagesFolder" value="packages" /> -->
<add key="globalPackagesFolder" value="packages" />
<add key="repositoryPath" value="packages" />

<!-- This is a workaround for Azure Artifacts, see: https://github.com./dotnet/arcade/issues/4190, https://github.com./dotnet/core-eng/issues/9681 -->
<add key='maxHttpRequestsPerSource' value='2' />
</config>
Expand Down
183 changes: 102 additions & 81 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Build script for MSTest Test Framework.

[CmdletBinding(PositionalBinding=$false)]
[CmdletBinding(PositionalBinding = $false)]
Param(
[ValidateSet("Debug", "Release")]
[Alias("c")]
Expand All @@ -18,7 +18,7 @@ Param(
[Alias("vs")]
[string] $VersionSuffix = "dev",

[string] $BuildVersionPrefix = "14.0",
[string] $BuildVersionPrefix = "14.0",

[string] $BuildVersionSuffix = "9999.99",

Expand Down Expand Up @@ -47,7 +47,13 @@ Param(
[Switch] $IsLocalizedBuild,

[Alias("tpv")]
[string] $TestPlatformVersion = $null
[string] $TestPlatformVersion = $null,

[Alias("f")]
[Switch] $Force,

[Alias("s")]
[String[]] $Steps = @("UpdateTPVersion", "Restore", "Build", "Publish")
)

. $PSScriptRoot\common.lib.ps1
Expand All @@ -73,7 +79,7 @@ $TFB_Solutions = @(
"TestFx.sln"
)

$TFB_NetCoreProjects =@(
$TFB_NetCoreProjects = @(
"src\Adapter\PlatformServices.NetCore\PlatformServices.NetCore.csproj"

"test\ComponentTests\TestAssets\TestProjectForAssemblyResolution\TestProjectForAssemblyResolution.csproj"
Expand Down Expand Up @@ -132,8 +138,7 @@ function Perform-Restore {

Write-Log "Perform-Restore: Started."

if($TFB_SkipRestore)
{
if ($TFB_SkipRestore) {
Write-Log "Perform-Restore: Skipped."
return;
}
Expand All @@ -159,12 +164,11 @@ function Perform-Restore {
$msbuildPath = Locate-MSBuildPath

Write-Verbose "Starting solution restore..."
foreach($solution in $TFB_Solutions)
{
$solutionPath = Locate-Item -relativePath $solution
foreach ($solution in $TFB_Solutions) {
$solutionPath = Locate-Item -relativePath $solution

Write-Verbose "$nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath"
& $nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath
Write-Verbose "$nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath"
& $nuget restore -msbuildPath $msbuildPath -verbosity quiet -nonInteractive -configFile $nugetConfig $solutionPath
}

if ($lastExitCode -ne 0) {
Expand All @@ -174,8 +178,7 @@ function Perform-Restore {
$msbuild = Join-Path $msbuildPath "MSBuild.exe"

Write-Verbose "Starting restore for NetCore Projects"
foreach($project in $TFB_NetCoreProjects)
{
foreach ($project in $TFB_NetCoreProjects) {
$projectPath = Locate-Item -relativePath $project

Write-Verbose "$msbuild /t:restore -verbosity:minimal $projectPath /m"
Expand All @@ -197,16 +200,13 @@ function Perform-Build {

Write-Log "Perform-Build: Started."

if($TFB_Clean)
{
if ($TFB_Clean) {
$foldersToDel = @( $TFB_Configuration, "TestAssets" )
Write-Log " Clean build requested."
foreach($folder in $foldersToDel)
{
foreach ($folder in $foldersToDel) {
$outDir = Join-Path $env:TF_OUT_DIR -ChildPath $folder

if(Test-Path $outDir)
{

if (Test-Path $outDir) {
Write-Output " Deleting $outDir"
Remove-Item -Recurse -Force $outDir
}
Expand All @@ -218,87 +218,81 @@ function Perform-Build {
Write-Log "Perform-Build: Completed. {$(Get-ElapsedTime($timer))}"
}

function Invoke-Build([string] $solution, $hasVsixExtension = "false")
{
function Invoke-Build([string] $solution, $hasVsixExtension = "false") {
$msbuild = Locate-MSBuild -hasVsixExtension $hasVsixExtension
$solutionPath = Locate-Item -relativePath $solution
$solutionPath = Locate-Item -relativePath $solution
$solutionDir = [System.IO.Path]::GetDirectoryName($solutionPath)
$solutionSummaryLog = Join-Path -path $solutionDir -childPath "msbuild.log"
$solutionWarningLog = Join-Path -path $solutionDir -childPath "msbuild.wrn"
$solutionFailureLog = Join-Path -path $solutionDir -childPath "msbuild.err"

Write-Log " Building $solution..."
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m"
& $msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m
Write-Log " Building $solution..."
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m"
& $msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath /bl /m

if ($lastExitCode -ne 0) {
throw "Build failed with an exit code of '$lastExitCode'."
}
if ($lastExitCode -ne 0) {
throw "Build failed with an exit code of '$lastExitCode'."
}
}

#
# Creates Fx & Adapter nuget packages
#
function Create-NugetPackages
{
$timer = Start-Timer
function Create-NugetPackages {
$timer = Start-Timer

Write-Log "Create-NugetPackages: Started."
Write-Log "Create-NugetPackages: Started."

$stagingDir = Join-Path $env:TF_OUT_DIR $TFB_Configuration
$packageOutDir = Join-Path $stagingDir "MSTestPackages"
$tfSrcPackageDir = Join-Path $env:TF_SRC_DIR "Package"
$stagingDir = Join-Path $env:TF_OUT_DIR $TFB_Configuration
$packageOutDir = Join-Path $stagingDir "MSTestPackages"
$tfSrcPackageDir = Join-Path $env:TF_SRC_DIR "Package"

# Copy over the nuspecs to the staging directory
if($TFB_Official)
{
$nuspecFiles = @("MSTest.TestAdapter.Dotnet.nuspec", "MSTest.TestAdapter.nuspec", "MSTest.TestAdapter.symbols.nuspec", "MSTest.TestFramework.nuspec", "MSTest.TestFramework.symbols.nuspec", "MSTest.Internal.TestFx.Documentation.nuspec")
}
else
{
$nuspecFiles = @("MSTest.TestAdapter.Enu.nuspec","MSTest.TestFramework.enu.nuspec", "MSTest.TestAdapter.Dotnet.nuspec")
}
# Copy over the nuspecs to the staging directory
if ($TFB_Official) {
$nuspecFiles = @("MSTest.TestAdapter.Dotnet.nuspec", "MSTest.TestAdapter.nuspec", "MSTest.TestAdapter.symbols.nuspec", "MSTest.TestFramework.nuspec", "MSTest.TestFramework.symbols.nuspec", "MSTest.Internal.TestFx.Documentation.nuspec")
}
else {
$nuspecFiles = @("MSTest.TestAdapter.Enu.nuspec", "MSTest.TestFramework.enu.nuspec", "MSTest.TestAdapter.Dotnet.nuspec")
}

foreach ($file in $nuspecFiles) {
Copy-Item $tfSrcPackageDir\$file $stagingDir -Force
}
foreach ($file in $nuspecFiles) {
Copy-Item $tfSrcPackageDir\$file $stagingDir -Force
}

# Copy over LICENSE.txt file to staging directory
$licenseFilePath = Join-Path $env:TF_ROOT_DIR "LICENSE.txt"
Copy-Item $licenseFilePath $stagingDir -Force
# Copy over LICENSE.txt file to staging directory
$licenseFilePath = Join-Path $env:TF_ROOT_DIR "LICENSE.txt"
Copy-Item $licenseFilePath $stagingDir -Force

# Call nuget pack on these components.
$nugetExe = Locate-Nuget
# Call nuget pack on these components.
$nugetExe = Locate-Nuget

foreach ($file in $nuspecFiles) {
$version = $TFB_FrameworkVersion
foreach ($file in $nuspecFiles) {
$version = $TFB_FrameworkVersion

if($file.Contains("TestAdapter"))
{
$version = $TFB_AdapterVersion
}

if(![string]::IsNullOrEmpty($TFB_VersionSuffix))
{
$versionSuffix = $TFB_VersionSuffix -replace "\.","-"
$version = $version + "-" + $versionSuffix
}

Write-Verbose "$nugetExe pack $stagingDir\$file -OutputDirectory $packageOutDir -Version=$version -Properties Version=$version"
& $nugetExe pack $stagingDir\$file -OutputDirectory $packageOutDir -Version $version -Properties Version=$version`;Srcroot=$env:TF_SRC_DIR`;Packagesroot=$env:TF_PACKAGES_DIR

if ($lastExitCode -ne 0) {
throw "Nuget pack failed with an exit code of '$lastExitCode'."
}
if ($file.Contains("TestAdapter")) {
$version = $TFB_AdapterVersion
}

if (![string]::IsNullOrEmpty($TFB_VersionSuffix)) {
$versionSuffix = $TFB_VersionSuffix -replace "\.", "-"
$version = $version + "-" + $versionSuffix
}

Write-Verbose "$nugetExe pack $stagingDir\$file -OutputDirectory $packageOutDir -Version=$version -Properties Version=$version"
& $nugetExe pack $stagingDir\$file -OutputDirectory $packageOutDir -Version $version -Properties Version=$version`;Srcroot=$env:TF_SRC_DIR`;Packagesroot=$env:TF_PACKAGES_DIR

if ($lastExitCode -ne 0) {
throw "Nuget pack failed with an exit code of '$lastExitCode'."
}
}

Write-Log "Create-NugetPackages: Complete. {$(Get-ElapsedTime($timer))}"
Write-Log "Create-NugetPackages: Complete. {$(Get-ElapsedTime($timer))}"
}

function Replace-InFile($File, $RegEx, $ReplaceWith) {
$content = Get-Content -Raw -Encoding utf8 $File
$newContent = ($content -replace $RegEx,$ReplaceWith)
if(-not $content.Equals($newContent)) {
$newContent = ($content -replace $RegEx, $ReplaceWith)
if (-not $content.Equals($newContent)) {
Write-Log "Updating TestPlatform version in $File"
$newContent | Set-Content -Encoding utf8 $File -NoNewline
}
Expand All @@ -313,19 +307,46 @@ function Sync-PackageVersions {

if ([String]::IsNullOrWhiteSpace($TestPlatformVersion)) {
$TestPlatformVersion = (([XML](Get-Content $versionsFile)).Project.PropertyGroup.TestPlatformVersion).InnerText
} else {
}
else {
Replace-InFile -File $versionsFile -RegEx $versionsRegex -ReplaceWith "<`$1>$TestPlatformVersion</TestPlatformVersion>"
}

(Get-ChildItem "$PSScriptRoot\..\src\*packages.config","$PSScriptRoot\..\test\*packages.config" -Recurse) | ForEach-Object {
(Get-ChildItem "$PSScriptRoot\..\src\*packages.config", "$PSScriptRoot\..\test\*packages.config" -Recurse) | ForEach-Object {
Replace-InFile -File $_ -RegEx $packageRegex -ReplaceWith ('<package id="Microsoft.TestPlatform$1" version="{0}"' -f $TestPlatformVersion)
}

Replace-InFile -File "$PSScriptRoot\..\test\E2ETests\Automation.CLI\CLITestBase.cs" -RegEx $sourceRegex -ReplaceWith ('$1Microsoft.TestPlatform.{0}";' -f $TestPlatformVersion)
}

function ShouldRunStep([string[]]$CurrentSteps) {
if ($Force) {
return $true
}

foreach ($step in $CurrentSteps) {
if ($Steps -contains $step) {
return $true
}
}

return $false
}

Print-Help
Sync-PackageVersions
Perform-Restore
Perform-Build
Create-NugetPackages

if (ShouldRunStep @("UpdateTPVersion")) {
Sync-PackageVersions
}

if (ShouldRunStep @("UpdateTPVersion", "Restore")) {
Perform-Restore
}

if (ShouldRunStep @("Build")) {
Perform-Build
}

if (ShouldRunStep @("Publish")) {
Create-NugetPackages
}
2 changes: 1 addition & 1 deletion scripts/build/TestFx.Versions.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestPlatformVersion Condition=" '$(TestPlatformVersion)' == '' ">16.9.0-preview-20201215-01</TestPlatformVersion>
<TestPlatformVersion Condition=" '$(TestPlatformVersion)' == '' ">16.9.0-preview-20210129-05</TestPlatformVersion>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
</PropertyGroup>
</Project>
32 changes: 32 additions & 0 deletions src/Adapter/MSTest.CoreAdapter/Extensions/TestCaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions
{
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

using Constants = Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Constants;
using ManagedNameUtilities = Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities;

/// <summary>
/// Extension Methods for TestCase Class
/// </summary>
internal static class TestCaseExtensions
{
internal static readonly TestProperty ManagedTypeProperty = TestProperty.Register(
id: ManagedNameUtilities.Contants.ManagedTypePropertyId,
label: ManagedNameUtilities.Contants.ManagedTypeLabel,
category: string.Empty,
description: string.Empty,
valueType: typeof(string),
validateValueCallback: o => !string.IsNullOrWhiteSpace(o as string),
attributes: TestPropertyAttributes.Hidden,
owner: typeof(TestCase));

internal static readonly TestProperty ManagedMethodProperty = TestProperty.Register(
id: ManagedNameUtilities.Contants.ManagedMethodPropertyId,
label: ManagedNameUtilities.Contants.ManagedMethodLabel,
category: string.Empty,
description: string.Empty,
valueType: typeof(string),
validateValueCallback: o => !string.IsNullOrWhiteSpace(o as string),
attributes: TestPropertyAttributes.Hidden,
owner: typeof(TestCase));

/// <summary>
/// The to unit test element.
/// </summary>
Expand Down Expand Up @@ -48,5 +70,15 @@ internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string

return testElement;
}

internal static string GetManagedType(this TestCase testCase) => testCase.GetPropertyValue<string>(ManagedTypeProperty, null);

internal static void SetManagedType(this TestCase testCase, string value) => testCase.SetPropertyValue<string>(ManagedTypeProperty, value);

internal static string GetManagedMethod(this TestCase testCase) => testCase.GetPropertyValue<string>(ManagedMethodProperty, null);

internal static void SetManagedMethod(this TestCase testCase, string value) => testCase.SetPropertyValue<string>(ManagedMethodProperty, value);

internal static bool ContainsManagedMethodAndType(this TestCase testCase) => !string.IsNullOrWhiteSpace(testCase.GetManagedMethod()) && !string.IsNullOrWhiteSpace(testCase.GetManagedType());
}
}
5 changes: 3 additions & 2 deletions src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.AdapterUtilities" Version="$(TestPlatformVersion)" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(TestPlatformVersion)" />
<PackageReference Include="MicroBuild.Core" Version="0.2.0" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -138,7 +139,7 @@
<PropertyGroup>
<SourcePath>$(ProjectDir)..\Build</SourcePath>
<PostBuildEvent>
xcopy /Y /I /S /E "$(SourcePath)" "$(OutDir)..\Build"
</PostBuildEvent>
xcopy /Y /I /S /E "$(SourcePath)" "$(OutDir)..\Build"
</PostBuildEvent>
</PropertyGroup>
</Project>
Loading