Skip to content

Commit

Permalink
Optimize the referenced wcf package version and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
imcarolwang committed May 9, 2024
1 parent a653daa commit e14cd33
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.ServiceModel;
using System.Threading.Tasks;
using System.Linq;
using System.Xml.Linq;
using static Microsoft.Tools.ServiceModel.Svcutil.TargetFrameworkHelper;

namespace Microsoft.Tools.ServiceModel.Svcutil
{
Expand All @@ -32,7 +32,18 @@ public AddAsyncOpenClose(CommandProcessorOptions options)
{
if (options.TargetFramework.IsDnx)
{
if (TargetFrameworkHelper.NetCoreVersionReferenceTable.TryGetValue(options.TargetFramework.Version, out var referenceTable))
bool findVersion = false;
System.Collections.Generic.List<ProjectDependency> referenceTable = null;
if(options.TargetFramework.Name != FrameworkInfo.Netstandard)
{
findVersion = NetCoreVersionReferenceTable.TryGetValue(options.TargetFramework.Version, out referenceTable);
}
else if (NetStandardToNetCoreVersionMap.Keys.Contains(options.TargetFramework.Version))
{
findVersion = NetCoreVersionReferenceTable.TryGetValue(NetCoreToWCFPackageReferenceVersionMap[NetStandardToNetCoreVersionMap[options.TargetFramework.Version]], out referenceTable);
}

if (findVersion)
{
string version = referenceTable.FirstOrDefault().Version;
string[] vers = version.Split('.');
Expand Down
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
57 changes: 34 additions & 23 deletions src/dotnet-svcutil/lib/src/Shared/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ 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("5.1") },
{new Version("2.1"), new Version("5.1") }
});

public static ReadOnlyDictionary<Version, Version> NetCoreToWCFPackageReferenceVersionMap { get; } = new ReadOnlyDictionary<Version, Version>(new SortedDictionary<Version, Version>
{
{new Version("1.0"), new Version("1.0") },
{new Version("1.1"), new Version("1.1") },
{new Version("2.0"), new Version("2.0") },
{new Version("2.1"), new Version("2.1") },
{new Version("2.2"), new Version("2.1") },
{new Version("3.0"), new Version("2.1") },
{new Version("3.1"), new Version("3.1") },
{new Version("5.0"), new Version("5.0") },
{new Version("5.1"), new Version("5.1") },
{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>>
Expand Down Expand Up @@ -65,16 +82,14 @@ internal class TargetFrameworkHelper
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.8.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "4.8.*")
} },
{new Version("6.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("5.1"), new List<ProjectDependency> {
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("7.0"), new List<ProjectDependency> {
{new Version("6.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.*"),
Expand Down Expand Up @@ -116,7 +131,7 @@ internal class TargetFrameworkHelper

public static Version MinSupportedNetFxVersion { get; } = new Version("4.5");
public static Version MinSupportedNetStandardVersion { get; } = NetStandardToNetCoreVersionMap.Keys.First();
public static Version MinSupportedNetCoreAppVersion { get; } = NetStandardToNetCoreVersionMap.Values.First();
public static Version MinSupportedNetCoreAppVersion { get; } = NetCoreToWCFPackageReferenceVersionMap.Keys.First();

public static IEnumerable<ProjectDependency> GetWcfProjectReferences(string targetFramework)
{
Expand All @@ -126,9 +141,13 @@ public static IEnumerable<ProjectDependency> GetWcfProjectReferences(string targ
{
if (frameworkInfo.IsDnx)
{
if (NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
if(frameworkInfo.Name == FrameworkInfo.Netstandard && TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Contains(frameworkInfo.Version))
{
dependencies = NetCoreVersionReferenceTable[NetCoreToWCFPackageReferenceVersionMap[NetStandardToNetCoreVersionMap[frameworkInfo.Version]]];
}
else if(frameworkInfo.Name != FrameworkInfo.Netstandard && NetCoreToWCFPackageReferenceVersionMap.ContainsKey(frameworkInfo.Version))
{
dependencies = NetCoreVersionReferenceTable[frameworkInfo.Version];
dependencies = NetCoreVersionReferenceTable[NetCoreToWCFPackageReferenceVersionMap[frameworkInfo.Version]];
}
else
{
Expand Down Expand Up @@ -190,16 +209,8 @@ public static Version GetLowestNetCoreVersion(IEnumerable<string> targetFramewor
}
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))
{
netCoreVersion = frameworkInfo.Version;
}
else
{
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
}
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
}

if (targetVersion == null || targetVersion > netCoreVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ServiceReference
{
using System.Runtime.Serialization;


[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.Runtime.Serialization.DataContractAttribute(Name="BinLibrary", Namespace="http://schemas.datacontract.org/2004/07/BinLib")]
public partial class BinLibrary : object
{

private string ValueField;

[System.Runtime.Serialization.DataMemberAttribute()]
public string Value
{
get
{
return this.ValueField;
}
set
{
this.ValueField = value;
}
}
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.Runtime.Serialization.DataContractAttribute(Name="TypeReuseCompositeType", Namespace="http://schemas.datacontract.org/2004/07/TypesLib")]
public partial class TypeReuseCompositeType : object
{

private bool BoolValueField;

private string StringValueField;

[System.Runtime.Serialization.DataMemberAttribute()]
public bool BoolValue
{
get
{
return this.BoolValueField;
}
set
{
this.BoolValueField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string StringValue
{
get
{
return this.StringValueField;
}
set
{
this.StringValueField = value;
}
}
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference.ITypeReuseSvc")]
public interface ITypeReuseSvc
{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITypeReuseSvc/GetData", ReplyAction="http://tempuri.org/ITypeReuseSvc/GetDataResponse")]
System.Threading.Tasks.Task<ServiceReference.BinLibrary> GetDataAsync(int value);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITypeReuseSvc/GetDataUsingDataContract", ReplyAction="http://tempuri.org/ITypeReuseSvc/GetDataUsingDataContractResponse")]
System.Threading.Tasks.Task<ServiceReference.TypeReuseCompositeType> GetDataUsingDataContractAsync(ServiceReference.TypeReuseCompositeType composite);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public interface ITypeReuseSvcChannel : ServiceReference.ITypeReuseSvc, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public partial class TypeReuseSvcClient : System.ServiceModel.ClientBase<ServiceReference.ITypeReuseSvc>, ServiceReference.ITypeReuseSvc
{

/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

public TypeReuseSvcClient() :
base(TypeReuseSvcClient.GetDefaultBinding(), TypeReuseSvcClient.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), TypeReuseSvcClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}

public System.Threading.Tasks.Task<ServiceReference.BinLibrary> GetDataAsync(int value)
{
return base.Channel.GetDataAsync(value);
}

public System.Threading.Tasks.Task<ServiceReference.TypeReuseCompositeType> GetDataUsingDataContractAsync(ServiceReference.TypeReuseCompositeType composite)
{
return base.Channel.GetDataUsingDataContractAsync(composite);
}

public virtual System.Threading.Tasks.Task OpenAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}

public virtual System.Threading.Tasks.Task CloseAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc))
{
return new System.ServiceModel.EndpointAddress("http://localhost:51074/TypeReuseSvc.svc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return TypeReuseSvcClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc);
}

private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return TypeReuseSvcClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc);
}

public enum EndpointConfiguration
{

BasicHttpBinding_ITypeReuseSvc,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
"version": "99.99.99",
"options": {
"inputs": [
"$testCasesPath$/wsdl/Simple.wsdl"
],
"namespaceMappings": [
"*, ServiceReference"
],
"outputFile": "Reference.cs",
"targetFramework": "N.N",
"typeReuseMode": "All"
}
}
Loading

0 comments on commit e14cd33

Please sign in to comment.