Skip to content

Commit

Permalink
Changed new configurator method name (#2397) (#2403)
Browse files Browse the repository at this point in the history
* Changed new configurator method name

* added more robust heck for target framework

* default to FrameWork40

* fixed comment typo
  • Loading branch information
vritant24 committed Apr 15, 2020
1 parent e299415 commit 527fae3
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs
Expand Up @@ -52,17 +52,44 @@ public static string GenerateFakesSettingsForRunConfiguration(string[] sources,
doc.Load(xmlReader);
}

return !TryAddFakesDataCollectorSettings(doc, sources, GetFramework(runSettingsXml))
? runSettingsXml
: doc.OuterXml;
var frameworkVersion = GetFramework(runSettingsXml);
if (frameworkVersion == null)
{
return runSettingsXml;
}

return TryAddFakesDataCollectorSettings(doc, sources, (FrameworkVersion)frameworkVersion)
? doc.OuterXml
: runSettingsXml;
}

private static FrameworkVersion GetFramework(string runSettingsXml)
/// <summary>
/// returns FrameworkVersion contained in the runsettingsXML
/// </summary>
/// <param name="runSettingsXml"></param>
/// <returns></returns>
private static FrameworkVersion? GetFramework(string runSettingsXml)
{
var config = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettingsXml);
#pragma warning disable CS0618 // Type or member is obsolete
return config.TargetFrameworkVersion;
#pragma warning restore CS0618 // Type or member is obsolete
// We assume that only .NET Core, .NET Standard, or .NET Framework projects can have fakes.
var targetFramework = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettingsXml)?.TargetFramework;

if (targetFramework == null)
{
return null;
}

// Since there are no FrameworkVersion values for .Net Core 2.0 +, we check TargetFramework instead
// and default to FrameworkCore10 for .Net Core
if (targetFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 ||
targetFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0)
{
return FrameworkVersion.FrameworkCore10;
}

// Since the Datacollector is separated on the NetFramework/NetCore line, any value of NETFramework
// can be passed along to the fakes data collector configuration creator.
// We default to Framework40 to preserve back compat
return FrameworkVersion.Framework40;
}

/// <summary>
Expand Down

0 comments on commit 527fae3

Please sign in to comment.