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

dotnet-svcutil: refine TFX resolution and the referenced WCF versions, and update test baselines. #5653

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/dotnet-svcutil/lib/src/CommandProcessorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand Down Expand Up @@ -667,6 +668,18 @@ private async Task ProcessNamespaceMappingsOptionAsync(CancellationToken cancell

private async Task ProcessTargetFrameworkOptionAsync(CancellationToken cancellationToken)
{
if(this.Project != null)
{
this.Project.EndOfLifeTargetFrameworks?.ToList().ForEach(tfx => this.AddWarning(string.Format(CultureInfo.CurrentCulture, SR.WrnOutOfSupportTargetFrameworkFormat, tfx)));
}
else
{
if (TargetFrameworkHelper.IsEndofLifeFramework(this.TargetFramework?.FullName))
{
this.AddWarning(string.Format(CultureInfo.CurrentCulture, SR.WrnOutOfSupportTargetFrameworkFormat, this.TargetFramework.FullName));
}
}

if (this.TargetFramework == null)
{
var targetFrameworkMoniker = string.Empty;
Expand Down
5 changes: 4 additions & 1 deletion src/dotnet-svcutil/lib/src/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,7 @@ Your credentials will be sent to the server in clear text.</value>
<data name="WrnTargetFrameworkNotSupported_NetNamedPipe" xml:space="preserve">
<value>NetNamedPipe is not supported on current .net target framework.</value>
</data>
</root>
<data name="WrnOutOfSupportTargetFrameworkFormat" xml:space="preserve">
<value>The target framework '{0}' is out of support and will not receive security updates in the future.</value>
</data>
</root>
22 changes: 14 additions & 8 deletions src/dotnet-svcutil/lib/src/Shared/FrameworkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class FrameworkInfo
public const string Netstandard = "netstandard";
public const string Netcoreapp = "netcoreapp";
public const string Netfx = "net";
public const string Netframework = "netframework";
public const string Netversion = "version";

private FrameworkInfo()
Expand All @@ -24,7 +25,6 @@ private FrameworkInfo()
public string Name { get; private set; }
public Version Version { get; private set; }
public bool IsDnx { get; private set; }
public bool IsKnownDnx { get; private set; }

public static FrameworkInfo Parse(string fullFrameworkName)
{
Expand All @@ -40,6 +40,7 @@ public static FrameworkInfo Parse(string fullFrameworkName)
// framework spec form: 'net5.0'
// framework spec form: '.NETCoreApp,Version=v6.0'
// framework spec form: '.NETFramework,Version=v4.8'
// framework spec form: '.NETStandard,Version=v2.0'
// framework spec form: 'net7.0-windows10.0.19041.0', 'net7.0-windows'
for (int i = 0; i < fullFrameworkName.Length; i++)
{
Expand Down Expand Up @@ -76,16 +77,24 @@ public static FrameworkInfo Parse(string fullFrameworkName)

if (name.ToLower().Contains(Netversion))
{
//netcoreapp3.1 and lower
if (version.Major < 4)
//TFMoniker form ".NETStandard,Version=v2.0" resolves to framework name "netstandard."
if (name.ToLower().Contains(Netstandard))
{
name = Netcoreapp;
name = Netstandard;
}
else
//TFMoniker form ".NETFramework,Version=v4.8" resolves to framework name "net"
//TFMoniker form ".NETCoreApp,Version=v6.0" resolves to framework name "net"
else if (name.ToLower().Contains(Netframework) || version.Major >= 5)
{
name = Netfx;
}

//TFMoniker form ".NETCoreApp,Version=v3.1" resolves to framework name "netcoreapp"
else
{
name = Netcoreapp;
}

fullFrameworkName = string.Concat(name, version.ToString());
}

Expand All @@ -100,9 +109,6 @@ public static FrameworkInfo Parse(string fullFrameworkName)
fxInfo.Name = name;
fxInfo.Version = version;
fxInfo.IsDnx = name == Netstandard || name == Netcoreapp || version.Major >= 5;
fxInfo.IsKnownDnx = fxInfo.IsDnx &&
(TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Any((netstdVersion) => netstdVersion == version) ||
TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Values.Any((netcoreVersion) => netcoreVersion == version));

return fxInfo;
}
Expand Down
41 changes: 12 additions & 29 deletions src/dotnet-svcutil/lib/src/Shared/MSBuildProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public string TargetFramework
}

private List<string> _targetFrameworks = new List<string>();
private List<string> _endOfLifeTargetFrameworks = new List<string>();
public IEnumerable<string> TargetFrameworks { get { return _targetFrameworks; } }
internal IEnumerable<string> EndOfLifeTargetFrameworks { get { return _endOfLifeTargetFrameworks; } }

private string _runtimeIdentifier;
public string RuntimeIdentifier
Expand Down Expand Up @@ -133,17 +135,6 @@ private XElement PacakgeReferenceGroup
{
_packageReferenceGroup = refItems.FirstOrDefault().Parent;
}

FrameworkInfo netfxInfo = null;
FrameworkInfo dnxInfo = null;
if (this.TargetFrameworks.Count() > 1 && this.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out netfxInfo) && !netfxInfo.IsDnx))
{
var tfx = this.TargetFrameworks.FirstOrDefault(t => TargetFrameworkHelper.IsSupportedFramework(t, out dnxInfo) && dnxInfo.IsDnx);
if (!string.IsNullOrEmpty(tfx) && dnxInfo.Version.Major >= 6)
{
_packageReferenceGroup.Add(new XAttribute("Condition", $"'$(TargetFramework)' != '{netfxInfo.FullName}'"));
}
}
}

return _packageReferenceGroup;
Expand Down Expand Up @@ -242,9 +233,9 @@ public static async Task<MSBuildProj> ParseAsync(string projectText, string proj
}
else
{
msbuildProj._targetFramework = string.Concat("net", TargetFrameworkHelper.NetCoreVersionReferenceTable.LastOrDefault().Key.ToString());
msbuildProj._targetFramework = string.Concat("net", TargetFrameworkHelper.s_supportedVersions.First());
}

msbuildProj._targetFrameworks.Add(msbuildProj._targetFramework);
}

Expand Down Expand Up @@ -369,7 +360,13 @@ public static async Task<MSBuildProj> ParseAsync(string projectText, string proj

var sdkVersion = await ProjectPropertyResolver.GetSdkVersionAsync(msbuildProj.DirectoryPath, logger, cancellationToken).ConfigureAwait(false);
msbuildProj.SdkVersion = sdkVersion ?? string.Empty;

foreach (var tfx in msbuildProj._targetFrameworks)
{
if(TargetFrameworkHelper.IsEndofLifeFramework(tfx))
{
msbuildProj._endOfLifeTargetFrameworks.Add(tfx);
}
}
return msbuildProj;
}
}
Expand Down Expand Up @@ -541,21 +538,7 @@ public bool AddDependency(ProjectDependency dependency, bool copyInternalAssets
this.ProjectReferceGroup.Add(new XElement("ProjectReference", new XAttribute("Include", dependency.FullPath)));
break;
case ProjectDependencyType.Binary:
FrameworkInfo netfxInfo = null;
FrameworkInfo dnxInfo = null;
string dnxStr = this.TargetFrameworks.FirstOrDefault(t => TargetFrameworkHelper.IsSupportedFramework(t, out dnxInfo) && dnxInfo.IsDnx);
if (this.TargetFrameworks.Count() > 1 && dependency.Name.Equals(TargetFrameworkHelper.FullFrameworkReferences.FirstOrDefault().Name)
&& !string.IsNullOrWhiteSpace(dnxStr) && dnxInfo.Version.Major >= 6)
{
if (this.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out netfxInfo) && !netfxInfo.IsDnx))
{
this.ReferenceGroup.Add(new XElement("Reference", new XAttribute("Condition", $"'$(TargetFramework)' == '{netfxInfo.FullName}'"), new XAttribute("Include", dependency.AssemblyName), new XElement("HintPath", dependency.FullPath)));
}
}
else
{
this.ReferenceGroup.Add(new XElement("Reference", new XAttribute("Include", dependency.AssemblyName), new XElement("HintPath", dependency.FullPath)));
}
this.ReferenceGroup.Add(new XElement("Reference", new XAttribute("Include", dependency.AssemblyName), new XElement("HintPath", dependency.FullPath)));
break;
case ProjectDependencyType.Package:
this.PacakgeReferenceGroup.Add(new XElement("PackageReference", new XAttribute("Include", dependency.Name), new XAttribute("Version", dependency.Version)));
Expand Down
Loading
Loading