Skip to content
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

Added net7 support. #3944

Merged
merged 24 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions .editorconfig
Expand Up @@ -312,8 +312,8 @@ csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_prefer_local_over_anonymous_function = false:suggestion # not default, default is true, avoided because we use anonymous functions in multiple places and it does not make the code clearer
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_prefer_index_operator = false:warning # not default, default is true, disabled because Index operator is not supported in all the TFMs we support. (supported on .Net Core 3.0+)
csharp_style_prefer_range_operator = false:warning # not default, default is true, disabled because Range operator is not supported in all the TFMs we support. (supported on .Net Core 3.0+)
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
Expand All @@ -331,6 +331,9 @@ csharp_style_prefer_parameter_null_checking = false # not default, disabled as n
# IDE0055: Fix formatting - Set the severity of all .NET and C# formatting rules (https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules)
dotnet_diagnostic.IDE0055.severity = warning # ensure all formatting rules are enforced on build

# IDE0057: Use range operator
dotnet_diagnostic.IDE0057.severity = none # Range operator is not supported in some TFMs.

#### C# Formatting Rules ####

# New line preferences
Expand Down
2 changes: 1 addition & 1 deletion playground/MSTest1/MSTest1.csproj
Expand Up @@ -6,7 +6,7 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />

<PropertyGroup>
<TargetFrameworks>$(TargetFrameworks);net472;net5.0</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);net472;net5.0;net6.0;net7.0</TargetFrameworks>
Haplois marked this conversation as resolved.
Show resolved Hide resolved
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
<Prefer32Bit>false</Prefer32Bit>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/UnitTestProject/UnitTestProject.csproj
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\scripts\build\TestPlatform.Dependencies.props" />
<PropertyGroup>
<TargetFrameworks>$(TargetNetFxVersion);$(TargetNetCoreVersion)</TargetFrameworks>
<TargetFrameworks>$(TargetNetFxVersion);$(TargetNetCoreVersion);net7.0;net6.0;</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">$(TargetNetCoreVersion)</TargetFrameworks>
<OutputType Condition=" '$(TargetFramework)' != '$(TargetNetFxVersion)' ">Exe</OutputType>
<AssemblyName>UnitTestProject</AssemblyName>
Expand Down
8 changes: 4 additions & 4 deletions scripts/build.sh
Expand Up @@ -156,7 +156,7 @@ TPB_BRANCH="$(git -C "." rev-parse --abbrev-ref HEAD 2>/dev/null)" || TPB_BRANCH
TPB_COMMIT="$(git -C "." rev-parse HEAD 2>/dev/null)" || TPB_COMMIT="LOCALBUILD" # detached HEAD

if [[ $TP_USE_REPO_API = 1 ]]; then
TPB_TargetFrameworkCore="net6.0"
TPB_TargetFrameworkCore="net7.0"
fi

#
Expand Down Expand Up @@ -346,16 +346,16 @@ function publish_package()
cp -r src/testhost/bin/$TPB_Configuration/$TPB_TargetFramework/win7-x64/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/$TPB_TargetFramework/win7-x86/* $testhost
else
cp -r src/testhost/bin/$TPB_Configuration/net6.0/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/net6.0/* $testhost
cp -r src/testhost/bin/$TPB_Configuration/net7.0/* $testhost
cp -r src/testhost.x86/bin/$TPB_Configuration/net7.0/* $testhost
fi

# Copy over the logger assemblies to the Extensions folder.
local extensionsDir="$packageDir/Extensions"

if [[ $TP_USE_REPO_API = 1 ]]; then
log ".. Package: mv (Source Build)"
local current_tfn="net6.0"
local current_tfn="net7.0"
else
log ".. Package: mv"
local current_tfn="netstandard2.0"
Expand Down
11 changes: 0 additions & 11 deletions shared/NullableAttributes.cs
Expand Up @@ -3,9 +3,6 @@

// This was copied from https://github.com/dotnet/coreclr/blob/60f1e6265bd1039f023a82e0643b524d6aaf7845/src/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
// and updated to have the scope of the attributes be internal.

#pragma warning disable CA1019 // Define accessors for attribute arguments

namespace System.Diagnostics.CodeAnalysis;

#if NETFRAMEWORK || NETSTANDARD && !NETSTANDARD2_1 || NETCOREAPP && !NETCOREAPP3_0_OR_GREATER
Expand Down Expand Up @@ -149,11 +146,3 @@ public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
}

#endif

/// <summary>
/// Secret attribute that tells the CA1062 validate arguments rule that this method validates the argument is not null.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class ValidatedNotNullAttribute : Attribute
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
{
}
2 changes: 1 addition & 1 deletion src/AttachVS/AttachVS.csproj
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net472</TargetFrameworks>
<TargetFrameworks>net7;net472</TargetFrameworks>
<AssemblyName>AttachVS</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/AttachVS/AttachVs.cs
Expand Up @@ -133,9 +133,9 @@ private static bool AttachVs(Process vs, int pid)
{
try
{
dbg = dte.GetType().InvokeMember("Debugger", BindingFlags.GetProperty, null, dte, null, CultureInfo.InvariantCulture);
lps = dbg.GetType().InvokeMember("LocalProcesses", BindingFlags.GetProperty, null, dbg, null, CultureInfo.InvariantCulture);
var lpn = (System.Collections.IEnumerator)lps.GetType().InvokeMember("GetEnumerator", BindingFlags.InvokeMethod, null, lps, null, CultureInfo.InvariantCulture);
dbg = dte.GetType().InvokeMember("Debugger", BindingFlags.GetProperty, null, dte, null, CultureInfo.InvariantCulture)!;
lps = dbg.GetType().InvokeMember("LocalProcesses", BindingFlags.GetProperty, null, dbg, null, CultureInfo.InvariantCulture)!;
var lpn = (System.Collections.IEnumerator)lps.GetType().InvokeMember("GetEnumerator", BindingFlags.InvokeMethod, null, lps, null, CultureInfo.InvariantCulture)!;

while (lpn.MoveNext())
{
Expand Down
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<TargetFrameworks>$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<OutputType>Exe</OutputType>
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollectors/DumpMinitool.x86/DumpMinitool.x86.csproj
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<TargetFrameworks>$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
<OutputType>Exe</OutputType>
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollectors/DumpMinitool/DumpMinitool.csproj
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<TargetFrameworks>$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<OutputType>Exe</OutputType>
Expand Down
Expand Up @@ -335,7 +335,7 @@ private static ISet<string> ParseCommaSeparatedList(string commaSeparatedList)
return strings;
}

private void OnSessionStart(object sender, SessionStartEventArgs e)
private void OnSessionStart(object? sender, SessionStartEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
ValidateArg.NotNull(e.Context, "SessionStartEventArgs.Context");
Expand All @@ -345,7 +345,7 @@ private void OnSessionStart(object sender, SessionStartEventArgs e)
StartCollectionForContext(e.Context);
}

private void OnSessionEnd(object sender, SessionEndEventArgs e)
private void OnSessionEnd(object? sender, SessionEndEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
ValidateArg.NotNull(e.Context, "SessionEndEventArgs.Context");
Expand All @@ -355,7 +355,7 @@ private void OnSessionEnd(object sender, SessionEndEventArgs e)
WriteCollectedEventLogEntries(e.Context, true, TimeSpan.MaxValue, DateTime.UtcNow);
}

private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
private void OnTestCaseStart(object? sender, TestCaseStartEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
ValidateArg.NotNull(e.Context, "TestCaseStartEventArgs.Context");
Expand All @@ -371,7 +371,7 @@ private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
StartCollectionForContext(e.Context);
}

private void OnTestCaseEnd(object sender, TestCaseEndEventArgs e)
private void OnTestCaseEnd(object? sender, TestCaseEndEventArgs e)
{
ValidateArg.NotNull(e, nameof(e));
TPDebug.Assert(e.Context != null, "Context is null");
Expand Down Expand Up @@ -446,7 +446,7 @@ private void StartCollectionForContext(DataCollectionContext dataCollectionConte
var fileName = WriteEventLogs(eventLogEntries, isSessionEnd ? int.MaxValue : MaxEntries, dataCollectionContext, requestedDuration, timeRequestReceived);

// Add the directory to the list
_eventLogDirectories.Add(Path.GetDirectoryName(fileName));
_eventLogDirectories.Add(Path.GetDirectoryName(fileName)!);

lock (ContextMap)
{
Expand Down Expand Up @@ -568,23 +568,19 @@ private void ConfigureMaxEntries(CollectorNameValueConfigurationManager collecto

private EventLogSessionContext GetEventLogSessionContext(DataCollectionContext dataCollectionContext)
{
EventLogSessionContext eventLogSessionContext;
bool eventLogContainerFound;
lock (ContextMap)
{
eventLogContainerFound = ContextMap.TryGetValue(dataCollectionContext, out eventLogSessionContext);
if (ContextMap.TryGetValue(dataCollectionContext, out var eventLogSessionContext))
{
return eventLogSessionContext;
}
}

if (!eventLogContainerFound)
{
string msg = string.Format(
string msg = string.Format(
CultureInfo.CurrentCulture,
Resource.ContextNotFoundException,
dataCollectionContext.ToString());
throw new EventLogCollectorException(msg, null);
}

return eventLogSessionContext;
throw new EventLogCollectorException(msg, null);
}

}
Expand Up @@ -6,18 +6,12 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.TestPlatform.Extensions.EventLogCollector</AssemblyName>
<TargetFrameworks>$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<UseBannedApiAnalyzers>true</UseBannedApiAnalyzers>
</PropertyGroup>
<ItemGroup Condition=" '$(DotNetBuildFromSource)' != 'true' ">
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="System.Diagnostics.EventLog" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
@@ -0,0 +1 @@
#nullable enable
@@ -0,0 +1 @@
#nullable enable
Expand Up @@ -193,7 +193,7 @@ private static void GetManagedNameAndHierarchy(MethodBase method, bool useClosed
hierarchyValues[HierarchyConstants.Levels.TestGroupIndex] = managedMethodName.Substring(0, methodNameEndIndex);
hierarchyValues[HierarchyConstants.Levels.ClassIndex] = managedTypeName.Substring(hierarchyPos[1] + 1, hierarchyPos[2] - hierarchyPos[1] - 1);
hierarchyValues[HierarchyConstants.Levels.NamespaceIndex] = managedTypeName.Substring(hierarchyPos[0], hierarchyPos[1] - hierarchyPos[0]);
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType.GetTypeInfo().Assembly.GetName().Name;
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.GetTypeInfo()?.Assembly?.GetName()?.Name ?? string.Empty;
}

/// <summary>
Expand Down Expand Up @@ -411,7 +411,11 @@ private static void AppendMethodString(StringBuilder methodBuilder, string name,

if (arity > 0 && methodArity == arity)
{
methodBuilder.Append($"`{arity}");
methodBuilder.Append(
#if NET6_0_OR_GREATER
System.Globalization.CultureInfo.InvariantCulture,
#endif
$"`{arity}");
}
}

Expand Down
Expand Up @@ -5,8 +5,9 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<AssemblyName>Microsoft.TestPlatform.AdapterUtilities</AssemblyName>
<RootNamespace>Microsoft.TestPlatform.AdapterUtilities</RootNamespace>
</PropertyGroup>
Expand Down
Expand Up @@ -7,8 +7,8 @@
<PropertyGroup>
<NetStandardImplicitPackageVersion>2.0.0</NetStandardImplicitPackageVersion>
<AssemblyName>Microsoft.TestPlatform.Build</AssemblyName>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<UseBannedApiAnalyzers>true</UseBannedApiAnalyzers>
</PropertyGroup>
Expand Down
Expand Up @@ -52,7 +52,7 @@ public void UnregisterTestRunEvents(ITestRunRequest testRunRequest)
/// </summary>
/// <param name="sender"></param>
/// <param name="rawMessage">RawMessage from the testhost</param>
private void OnRawMessageReceived(object sender, string rawMessage)
private void OnRawMessageReceived(object? sender, string rawMessage)
{
// Directly send the data to translation layer instead of de-serializing it here
_designModeClient.SendRawMessage(rawMessage);
Expand Down
Expand Up @@ -6,8 +6,8 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.VisualStudio.TestPlatform.Client</AssemblyName>
<TargetFrameworks>netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<ItemGroup>
Expand Down
@@ -0,0 +1 @@
#nullable enable
@@ -0,0 +1 @@
#nullable enable
8 changes: 5 additions & 3 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Expand Up @@ -242,7 +242,7 @@ private void AddLoggerAssembliesFromSource(IEnumerable<string> sources, TestAdap

foreach (string source in sources)
{
string sourceDirectory = Path.GetDirectoryName(source);
var sourceDirectory = Path.GetDirectoryName(source);
if (!string.IsNullOrEmpty(sourceDirectory) && _fileHelper.DirectoryExists(sourceDirectory))
{
SearchOption searchOption = GetSearchOption(strategy, SearchOption.TopDirectoryOnly);
Expand Down Expand Up @@ -291,15 +291,17 @@ private static void AddExtensionAssembliesFromExtensionDirectory()
.Union(defaultExtensionPaths);
}

string extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation()), "Extensions");
string extensionsFolder = Path.Combine(
Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation())!,
"Extensions");
if (!fileHelper.DirectoryExists(extensionsFolder))
{
// TODO: Since we no-longer run from <playground>\vstest.console\vstest.conosle.exe in Playground, the relative
// extensions folder location changed and we need to patch it. This should be a TEMPORARY solution though, we
// should come up with a better way of fixing this.
// NOTE: This is specific to Playground which references vstest.console from a location that doesn't contain
// the Extensions folder. Normal projects shouldn't have this issue.
extensionsFolder = Path.Combine(Path.GetDirectoryName(extensionsFolder), "vstest.console", "Extensions");
extensionsFolder = Path.Combine(Path.GetDirectoryName(extensionsFolder)!, "vstest.console", "Extensions");
}

if (fileHelper.DirectoryExists(extensionsFolder))
Expand Down
Expand Up @@ -290,7 +290,12 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC
ex.ToString(),
uri,
friendlyName,
Guid.Parse(testCaseId));
Guid.Parse(testCaseId
#if NET7_0_OR_GREATER
, CultureInfo.InvariantCulture
#endif
)
);

throw;
}
Expand Down
Expand Up @@ -20,7 +20,7 @@ internal class DataCollectionTelemetryManager : IDataCollectionTelemetryManager
private const string ClrIeInstrumentationMethodConfigurationPrefix32Variable = "MicrosoftInstrumentationEngine_ConfigPath32_";
private const string ClrIeInstrumentationMethodConfigurationPrefix64Variable = "MicrosoftInstrumentationEngine_ConfigPath64_";

private static readonly Guid ClrIeProfilerGuid = Guid.Parse("{324f817a-7420-4e6d-b3c1-143fbed6d855}");
private static readonly Guid ClrIeProfilerGuid = new("{324f817a-7420-4e6d-b3c1-143fbed6d855}");
private const string OverwrittenProfilerName = "overwritten";

private readonly IRequestData _requestData;
Expand Down
Expand Up @@ -6,8 +6,8 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<AssemblyName>Microsoft.VisualStudio.TestPlatform.Common</AssemblyName>
<TargetFrameworks>net6.0;netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net6.0</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;netstandard2.0;$(TargetNetFxVersion)</TargetFrameworks>
<TargetFrameworks Condition=" '$(DotNetBuildFromSource)' == 'true' ">net7.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<UseBannedApiAnalyzers>true</UseBannedApiAnalyzers>
</PropertyGroup>
Expand Down
@@ -0,0 +1 @@
#nullable enable
@@ -0,0 +1 @@
#nullable enable