Skip to content

Commit

Permalink
dotnet-svcutil: update NamedPipeMetadataImporter to remove the intern…
Browse files Browse the repository at this point in the history
…al asset folder. (dotnet#5582)

* dotnet-svcutil: update NamedPipeMetadataImporter to remove the internal asset folder.

* Remove unnecessary package branding properties.

* Update folder name from internalAssets to dependencies.

* update: directly packaging without copying NamedPipeMetadataImporter binary.

* update.

* Update: handle 6.0 and 8.0 target framework projects properly.

* update.
  • Loading branch information
imcarolwang authored and organich committed Aug 31, 2024
1 parent c8407ba commit 04a3bee
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 26 deletions.
6 changes: 6 additions & 0 deletions dotnet-svcutil.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-svcutil", "src\dotne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-svcutil-lib.Tests", "src\dotnet-svcutil\lib\tests\src\dotnet-svcutil-lib.Tests.csproj", "{41376AC5-871E-4CAB-BCF9-1D5CD3351A90}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Svcutil.NamedPipeMetadataImporter", "src\dotnet-svcutil\lib\Microsoft.Svcutil.NamedPipeMetadataImporter\Microsoft.Svcutil.NamedPipeMetadataImporter.csproj", "{0EAB34F1-983D-4E18-B052-BDBE100DA83F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{41376AC5-871E-4CAB-BCF9-1D5CD3351A90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41376AC5-871E-4CAB-BCF9-1D5CD3351A90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41376AC5-871E-4CAB-BCF9-1D5CD3351A90}.Release|Any CPU.Build.0 = Release|Any CPU
{0EAB34F1-983D-4E18-B052-BDBE100DA83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EAB34F1-983D-4E18-B052-BDBE100DA83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EAB34F1-983D-4E18-B052-BDBE100DA83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EAB34F1-983D-4E18-B052-BDBE100DA83F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<PropertyGroup>
<AssemblyVersionFile>$(IntermediateOutputPath)\$(TargetFramework)\$(MSBuildProjectName).$(TargetFramework).version.cs</AssemblyVersionFile>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;net462</TargetFrameworks>
<RootNamespace>Microsoft.Tools.ServiceModel.Svcutil</RootNamespace>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.0.*" Condition="'$(TargetFramework)' == 'net6.0'">
<PrivateAssets>contentfiles;analyzers;build</PrivateAssets>
</PackageReference>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.*" Condition="'$(TargetFramework)' == 'net6.0'">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="8.*" Condition="'$(TargetFramework)' == 'net8.0'">
<IncludeAssets>all</IncludeAssets>
</PackageReference>
<Reference Include="System.ServiceModel" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>
</ItemGroup>
<PropertyGroup>
<DotNetUseShippingVersions>true</DotNetUseShippingVersions>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<IncludeSymbols>true</IncludeSymbols>
<IncludeSource>false</IncludeSource>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class NamedPipeMetadataImporter
const string BindingNamespace = "http://schemas.microsoft.com/ws/2005/02/mex/bindings";
XmlReader _xmlReader;

#if NET6_0
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public XmlReader GetReader(Uri uri)
{
return GetMetadatadataAsync(uri).GetAwaiter().GetResult();
}

#if NET6_0
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public async Task<XmlReader> GetMetadatadataAsync(Uri uri)
Expand Down Expand Up @@ -77,7 +77,7 @@ public void RequestCallback(IAsyncResult result)
}
}

#if NET6_0
#if NET6_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public CustomBinding CreateNamedPipeBinding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void WsdlImported(WsdlImporter importer, Collection<ServiceEndpoint> endp

foreach (var binding in bindings)
{
if (binding is NetNamedPipeBinding && _options.Project != null && !_options.Project.TargetFrameworks.Any(t => t.ToLower().Contains("windows")))
if (binding is NetNamedPipeBinding && _options.Project != null && (!_options.Project.TargetFrameworks.Any(t => t.ToLower().Contains("windows"))
|| !_options.Project.TargetFrameworks.Any(t => TargetFrameworkHelper.IsSupportedFramework(t, out FrameworkInfo fxInfo) && fxInfo.Version.Major >= 6)))
{
MetadataConversionError error = new MetadataConversionError(SR.WrnTargetFrameworkNotSupported_NetNamedPipe, isWarning: true);
if (!importer.Errors.Contains(error))
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-svcutil/lib/src/Metadata/ServiceDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public async Task ImportMetadataAsync(Action<WsdlImporter> onWsdlImporterCreated
}
else
{
tfn = "net6.0";
tfn = Environment.Version.Major >= 8 ? "net8.0" : "net6.0";
}

string toolPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Assembly assembly = Assembly.LoadFrom($"{toolPath}/internalAssets/{tfn}/Microsoft.Svcutil.NamedPipeMetadataImporter.dll");
Assembly assembly = Assembly.LoadFrom($"{toolPath}/{tfn}/Microsoft.Svcutil.NamedPipeMetadataImporter.dll");

Type type = assembly.GetType("Microsoft.Tools.ServiceModel.Svcutil.NamedPipeMetadataImporter");
if (type != null)
Expand Down
23 changes: 19 additions & 4 deletions src/dotnet-svcutil/lib/src/Shared/MSBuildProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,29 @@ public bool AddDependency(ProjectDependency dependency, bool copyInternalAssets

if(copyInternalAssets && dependency.AssemblyName == "dotnet-svcutil-lib")
{
switch(dependency.DependencyType)
string basePath;
string[] frameworks = { "net6.0", "net8.0", "net462" };
switch (dependency.DependencyType)
{
case ProjectDependencyType.Binary:
this.ReferenceGroup.Add(new XElement("Content", new XAttribute("CopyToOutputDirectory", "always"), new XAttribute("Include", Path.Combine(dependency.FullPath.Substring(0, dependency.FullPath.LastIndexOf(Path.DirectorySeparatorChar)), "internalAssets\\**")), new XAttribute("Link", "internalAssets/%(RecursiveDir)%(Filename)%(Extension)")));
basePath = dependency.FullPath.Substring(0, dependency.FullPath.LastIndexOf(Path.DirectorySeparatorChar));
foreach (var framework in frameworks)
{
this.ReferenceGroup.Add(new XElement("Content",
new XAttribute("CopyToOutputDirectory", "always"),
new XAttribute("Include", Path.Combine(basePath, $"{framework}\\**")),
new XAttribute("Link", $"{framework}/%(RecursiveDir)%(Filename)%(Extension)")));
}
break;
case ProjectDependencyType.Package:
string path = $"$(NuGetPackageRoot){dependency.Name}\\{dependency.Version}\\content\\internalAssets\\**";
this.PacakgeReferenceGroup.Add(new XElement("Content", new XAttribute("CopyToOutputDirectory", "always"), new XAttribute("Include", path), new XAttribute("Link", "internalAssets/%(RecursiveDir)%(Filename)%(Extension)")));
basePath = $"$(NuGetPackageRoot){dependency.Name}\\{dependency.Version}";
foreach (var framework in frameworks)
{
this.PacakgeReferenceGroup.Add(new XElement("Content",
new XAttribute("CopyToOutputDirectory", "always"),
new XAttribute("Include", $"{basePath}\\{framework}\\**"),
new XAttribute("Link", $"{framework}/%(RecursiveDir)%(Filename)%(Extension)")));
}
break;
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/dotnet-svcutil/lib/src/dotnet-svcutil-lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Reflection.DispatchProxy" Version="4.4.0" />
</ItemGroup>


<Target Name="PackAdditonalDlls" AfterTargets="build">
<ItemGroup>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net6.0\*.dll" Pack="true" PackagePath="net6.0"/>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net8.0\*.dll" Pack="true" PackagePath="net8.0"/>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net462\*.dll" Pack="true" PackagePath="net462"/>
</ItemGroup>
</Target>
<!-- Include resx files here so that arcade will handle them correctly. -->
<ItemGroup>
<EmbeddedResource Update="Bootstrapper\Resource.resx">
Expand Down Expand Up @@ -119,10 +126,4 @@
<ClassName>System.Web.Services.ResWebServices</ClassName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="internalAssets\**">
<Link>internalAssets/%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 16 additions & 1 deletion src/dotnet-svcutil/src/dotnet-svcutil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>


<Target Name="PackAdditonalDlls" AfterTargets="build">
<ItemGroup>
<TargetFrameworkItems Include="$(TargetFrameworks)" />
</ItemGroup>
<ItemGroup>
<TargetFrameworkItem Include="%(TargetFrameworkItems.Identity)">
<Tfx>%(TargetFrameworkItems.Identity)</Tfx>
</TargetFrameworkItem>
</ItemGroup>
<ItemGroup>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net6.0\*.dll" Pack="true" PackagePath="tools\%(TargetFrameworkItem.Tfx)\any\net6.0"/>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net8.0\*.dll" Pack="true" PackagePath="tools\%(TargetFrameworkItem.Tfx)\any\net8.0"/>
<None Include="$([System.IO.Path]::GetFullPath('$(ArtifactsBinDir)\'))\Microsoft.Svcutil.NamedPipeMetadataImporter\$(Configuration)\net462\*.dll" Pack="true" PackagePath="tools\%(TargetFrameworkItem.Tfx)\any\net462"/>
</ItemGroup>
</Target>

<ItemGroup>
<ProjectReference Include="..\lib\src\dotnet-svcutil-lib.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 04a3bee

Please sign in to comment.