Skip to content

Commit

Permalink
dotnet-svcutil: refine TFX resolution and the addition of WCF referen…
Browse files Browse the repository at this point in the history
…ce versions, and update test baselines.
  • Loading branch information
imcarolwang committed Sep 26, 2024
1 parent 2b6c6e3 commit 2f0f195
Show file tree
Hide file tree
Showing 58 changed files with 265 additions and 277 deletions.
21 changes: 15 additions & 6 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 @@ -40,6 +41,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,15 +78,22 @@ public static FrameworkInfo Parse(string fullFrameworkName)

if (name.ToLower().Contains(Netversion))
{
//netcoreapp3.1 and lower
if (version.Major < 4)
//.NETStandard,Version=v2.0 => netstandard2.0
if (name.ToLower().Contains(Netstandard))
{
name = Netcoreapp;
name = Netstandard;
}
else
//.NETFramework,Version=v4.8 => net4.8
//.NETCoreApp,Version=v6.0 => net6.0
else if (name.ToLower().Contains(Netframework) || version.Major >= 5)
{
name = Netfx;
}
//.NETCoreApp,Version=v3.1 => netcoreapp3.1
else
{
name = Netcoreapp;
}

fullFrameworkName = string.Concat(name, version.ToString());
}
Expand All @@ -101,8 +110,8 @@ public static FrameworkInfo Parse(string fullFrameworkName)
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));
((name == Netstandard && TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Any((netstdVersion) => netstdVersion == version)) ||
(name != Netstandard && TargetFrameworkHelper.NetCoreToWCFPackageReferenceVersionMap.Keys.Any((netcoreVersion) => netcoreVersion == version)));

return fxInfo;
}
Expand Down
20 changes: 8 additions & 12 deletions src/dotnet-svcutil/lib/src/Shared/MSBuildProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@ 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))
if (this.TargetFrameworks.Count() > 1 && this.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out FrameworkInfo netfxInfo) && !netfxInfo.IsDnx))
{
var tfx = this.TargetFrameworks.FirstOrDefault(t => TargetFrameworkHelper.IsSupportedFramework(t, out dnxInfo) && dnxInfo.IsDnx);
if (!string.IsNullOrEmpty(tfx) && dnxInfo.Version.Major >= 6)
Version ver = TargetFrameworkHelper.GetLowestNetCoreVersion(this.TargetFrameworks);
if (ver != null && ver.Major >= 6)
{
_packageReferenceGroup.Add(new XAttribute("Condition", $"'$(TargetFramework)' != '{netfxInfo.FullName}'"));
_packageReferenceGroup.Add(new XAttribute("Condition", $"!$(TargetFramework.StartsWith('net4'))"));
}
}
}
Expand Down Expand Up @@ -541,15 +539,13 @@ 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);
Version ver = TargetFrameworkHelper.GetLowestNetCoreVersion(this.TargetFrameworks);
if (this.TargetFrameworks.Count() > 1 && dependency.Name.Equals(TargetFrameworkHelper.FullFrameworkReferences.FirstOrDefault().Name)
&& !string.IsNullOrWhiteSpace(dnxStr) && dnxInfo.Version.Major >= 6)
&& ver != null && ver.Major >= 6)
{
if (this.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out netfxInfo) && !netfxInfo.IsDnx))
if (this.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out FrameworkInfo 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)));
this.ReferenceGroup.Add(new XElement("Reference", new XAttribute("Condition", $"$(TargetFramework.StartsWith('net4'))"), new XAttribute("Include", dependency.AssemblyName), new XElement("HintPath", dependency.FullPath)));
}
}
else
Expand Down
132 changes: 50 additions & 82 deletions src/dotnet-svcutil/lib/src/Shared/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,33 @@ internal class TargetFrameworkHelper
{new Version("1.5"), new Version("1.0") },
{new Version("1.6"), new Version("1.0") },
{new Version("1.6.1"), new Version("1.1") },
{new Version("2.0"), new Version("2.0") }
{new Version("2.0"), new Version("2.0") },
{new Version("2.1"), new Version("3.1") }
});

public static ReadOnlyDictionary<Version, Version> NetCoreToWCFPackageReferenceVersionMap { get; } = new ReadOnlyDictionary<Version, Version>(new SortedDictionary<Version, Version>
{
{new Version("1.0"), new Version("2.0") },
{new Version("1.1"), new Version("2.0") },
{new Version("2.0"), new Version("2.0") },
{new Version("2.1"), new Version("2.0") },
{new Version("2.2"), new Version("2.0") },
{new Version("3.0"), new Version("2.0") },
{new Version("3.1"), new Version("2.0") },
{new Version("5.0"), new Version("2.0") },
{new Version("6.0"), new Version("6.0") },
{new Version("7.0"), new Version("6.0") },
{new Version("8.0"), new Version("8.0") }
});

internal static SortedDictionary<Version, List<ProjectDependency>> NetCoreVersionReferenceTable = new SortedDictionary<Version, List<ProjectDependency>>
{
{new Version("1.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.0.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.1.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.1.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.0.*"),
ProjectDependency.FromPackage("System.Xml.XmlSerializer", "4.0.*" ),
} },
{new Version("1.1"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.3.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.3.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.3.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.3.*"),
ProjectDependency.FromPackage("System.Xml.XmlSerializer", "4.3.*" ),
} },
{new Version("2.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.4.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.4.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.4.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.4.*"),
} },
{new Version("2.1"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.6.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.6.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.6.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.6.*"),
} },
{new Version("3.1"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.7.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.7.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.7.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.7.*"),
} },
{new Version("5.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.8.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.8.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.8.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.8.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "4.8.*")
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.10.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "4.10.*")
} },
{new Version("6.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Http", "6.2.*"),
Expand All @@ -74,23 +58,11 @@ internal class TargetFrameworkHelper
ProjectDependency.FromPackage("System.ServiceModel.UnixDomainSocket", "6.2.*"),
ProjectDependency.FromPackage("System.Web.Services.Description", "6.2.*")
} },
{new Version("7.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Http", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetNamedPipe", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.Primitives", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.UnixDomainSocket", "6.2.*"),
ProjectDependency.FromPackage("System.Web.Services.Description", "6.2.*")
} },
{new Version("8.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Http", "8.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "8.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetNamedPipe", "8.*"),
ProjectDependency.FromPackage("System.ServiceModel.Primitives", "8.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "8.*"),
ProjectDependency.FromPackage("System.ServiceModel.UnixDomainSocket", "8.*"),
ProjectDependency.FromPackage("System.Web.Services.Description", "8.*")
ProjectDependency.FromPackage("System.ServiceModel.Primitives", "8.*")

} }
};

Expand Down Expand Up @@ -118,27 +90,17 @@ internal class TargetFrameworkHelper
public static Version MinSupportedNetStandardVersion { get; } = NetStandardToNetCoreVersionMap.Keys.First();
public static Version MinSupportedNetCoreAppVersion { get; } = NetStandardToNetCoreVersionMap.Values.First();

public static IEnumerable<ProjectDependency> GetWcfProjectReferences(string targetFramework)
public static IEnumerable<ProjectDependency> GetWcfProjectReferences(IEnumerable<string> targetFrameworks)
{
IEnumerable<ProjectDependency> dependencies = null;

if (IsSupportedFramework(targetFramework, out var frameworkInfo))
Version version = GetLowestNetCoreVersion(targetFrameworks);
if (version != null)
{
if (frameworkInfo.IsDnx)
{
if (NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
{
dependencies = NetCoreVersionReferenceTable[frameworkInfo.Version];
}
else
{
dependencies = NetCoreVersionReferenceTable.Last().Value;
}
}
else
{
dependencies = FullFrameworkReferences;
}
dependencies = NetCoreVersionReferenceTable[NetCoreToWCFPackageReferenceVersionMap[version]];
}
else
{
dependencies = FullFrameworkReferences;
}

return dependencies;
Expand Down Expand Up @@ -181,26 +143,32 @@ public static Version GetLowestNetCoreVersion(IEnumerable<string> targetFramewor
if (TargetFrameworkHelper.IsSupportedFramework(targetFramework, out var frameworkInfo) && frameworkInfo.IsDnx)
{
Version netCoreVersion;

if (frameworkInfo.IsKnownDnx)
{
netCoreVersion = frameworkInfo.Name == FrameworkInfo.Netstandard ?
TargetFrameworkHelper.NetStandardToNetCoreVersionMap[frameworkInfo.Version] :
frameworkInfo.Version;
}
else
{
// target framework is not the minumum standard supported netcore version but it is a known shipped netcore version.
if (TargetFrameworkHelper.NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
if (frameworkInfo.Name == FrameworkInfo.Netstandard)
{
netCoreVersion = frameworkInfo.Version;
if (!NetStandardToNetCoreVersionMap.TryGetValue(frameworkInfo.Version, out netCoreVersion))
{
netCoreVersion = NetStandardToNetCoreVersionMap.LastOrDefault().Value;
}
}
else
{
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
if (NetCoreToWCFPackageReferenceVersionMap.TryGetValue(frameworkInfo.Version, out Version version))
{
netCoreVersion = frameworkInfo.Version;
}
else
{
netCoreVersion = NetCoreToWCFPackageReferenceVersionMap.Keys.LastOrDefault();
}
}
}
else
{
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = NetCoreToWCFPackageReferenceVersionMap.Keys.LastOrDefault();
}

if (targetVersion == null || targetVersion > netCoreVersion)
{
Expand Down
6 changes: 3 additions & 3 deletions src/dotnet-svcutil/lib/src/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private static async Task<bool> AddProjectReferencesAsync(MSBuildProj project, C
{
try
{
var dependencies = TargetFrameworkHelper.GetWcfProjectReferences(project.TargetFramework);
var dependencies = TargetFrameworkHelper.GetWcfProjectReferences(project.TargetFrameworks);
if (dependencies != null)
{
bool needSave = false;
Expand All @@ -289,8 +289,8 @@ private static async Task<bool> AddProjectReferencesAsync(MSBuildProj project, C
if (project.TargetFrameworks.Count() > 1 && project.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out FrameworkInfo fxInfo) && !fxInfo.IsDnx))
{
FrameworkInfo fxInfo = null;
var tfx = project.TargetFrameworks.FirstOrDefault(t => TargetFrameworkHelper.IsSupportedFramework(t, out fxInfo) && fxInfo.IsDnx);
if (!string.IsNullOrEmpty(tfx) && fxInfo.Version.Major >= 6)
Version ver = TargetFrameworkHelper.GetLowestNetCoreVersion(project.TargetFrameworks);
if (ver != null && ver.Major >= 6)
{
needSave |= project.AddDependency(TargetFrameworkHelper.FullFrameworkReferences.FirstOrDefault());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="dotnet-svcutil-lib" Version="99.99.99" />
<Content CopyToOutputDirectory="always" Include="$(NuGetPackageRoot)dotnet-svcutil-lib/99.99.99/content/internalAssets/**" Link="internalAssets/%(RecursiveDir)%(Filename)%(Extension)" />
<Content CopyToOutputDirectory="always" Include="$(NuGetPackageRoot)dotnet-svcutil-lib/99.99.99/net6.0/**" Link="net6.0/%(RecursiveDir)%(Filename)%(Extension)" />
<Content CopyToOutputDirectory="always" Include="$(NuGetPackageRoot)dotnet-svcutil-lib/99.99.99/net8.0/**" Link="net8.0/%(RecursiveDir)%(Filename)%(Extension)" />
<Content CopyToOutputDirectory="always" Include="$(NuGetPackageRoot)dotnet-svcutil-lib/99.99.99/net462/**" Link="net462/%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.Web.Services.Description", Version="N.N.N">
</ItemGroup>
</Project>
Loading

0 comments on commit 2f0f195

Please sign in to comment.