Skip to content

Commit

Permalink
Merge pull request #4145 from StephenBonikowsky/stebon/master/Fixsvcu…
Browse files Browse the repository at this point in the history
…tilxmlserializertool

Fix pathing issues with the dotnet-svcutil.xmlserializer tool.
  • Loading branch information
StephenBonikowsky committed Feb 3, 2020
2 parents 99c0dad + 00e3191 commit eecebff
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
17 changes: 15 additions & 2 deletions src/svcutilcore/files/dotnet-svcutil.xmlserializer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@
<_SerializationAssemblyDisabledWarnings>$(NoWarn);219;162;$(SerializationAssemblyDisabledWarnings)</_SerializationAssemblyDisabledWarnings>
</PropertyGroup>

<UsingTask TaskName="Microsoft.NET.Build.Tasks.ResolvePackageAssets"
AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<Target Name="SvcUtilGenerateSerializationAssembly" AfterTargets="Build">
<ResolvePackageAssets
ProjectAssetsFile="$(ProjectAssetsFile)"
ProjectAssetsCacheFile="$(ProjectAssetsCacheFile)"
ProjectPath="$(MSBuildProjectFullPath)"
TargetFrameworkMoniker="$(NuGetTargetMoniker)"
DotNetAppHostExecutableNameWithoutExtension="$(_DotNetAppHostExecutableNameWithoutExtension)">
<Output
TaskParameter="RuntimeAssemblies"
ItemName="WCFRuntimeAssembly"/>
</ResolvePackageAssets>

<ItemGroup>
<_ReferenceAssembly Include="@(ReferencePath)"/>
<_ReferenceSMAssembly Include="@(_ReferenceAssembly)" Condition="$([System.String]::new('%(_ReferenceAssembly.Identity)').EndsWith('System.ServiceModel.Primitives.dll'))" />
<_ReferenceSMAssembly Include="@(WCFRuntimeAssembly)" />
</ItemGroup>

<Delete Condition="Exists('$(_SerializerDllIntermediateFolder)') == 'true'" Files="$(_SerializerDllIntermediateFolder)" ContinueOnError="true" />
Expand Down
42 changes: 18 additions & 24 deletions src/svcutilcore/src/Microsoft/Tools/ServiceModel/SvcUtil/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.Tools.ServiceModel.SvcUtil.XmlSerializer
using System.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -413,37 +414,30 @@ private void AddMscorlib(Dictionary<string, Type> foundCollectionTypes)

private void LoadSMReferenceAssembly()
{
IList<string> referencedAssembliesArgs = _arguments.GetArguments(Options.Cmd.SMReference);
string smReferenceArg = _arguments.GetArgument(Options.Cmd.SMReference);
IList<string> referencedAssembliesArgs = smReferenceArg.Split(':').ToList();
if (referencedAssembliesArgs != null && referencedAssembliesArgs.Count > 0)
{
string smassembly = referencedAssembliesArgs[0];
// Allow the reference to be for System.Private.ServiceModel as well.
if((smassembly.LastIndexOf("System.ServiceModel.Primitives", StringComparison.OrdinalIgnoreCase) == -1) && (smassembly.LastIndexOf("System.Private.ServiceModel", StringComparison.OrdinalIgnoreCase) == -1))
string smassembly = "";
string smpassembly = "";
foreach (string path in referencedAssembliesArgs)
{
ToolConsole.WriteError("Need to pass the right path of System.ServiceModel.Primitives for smreference parameter");
throw new ArgumentException("Invalid smreference value");
}
var file = new FileInfo(path);

string smpassembly = smassembly.Replace("System.ServiceModel.Primitives", "System.Private.ServiceModel");
//for some lowercase path
smpassembly = smpassembly.Replace("system.servicemodel.primitives", "system.private.servicemodel");

int refplace = smassembly.LastIndexOf("ref");
if(refplace > 0 )
{
smassembly = smassembly.Remove(refplace, 3).Insert(refplace, "lib");
refplace = smpassembly.LastIndexOf("ref");
smpassembly = smpassembly.Remove(refplace, 3).Insert(refplace, "lib");
int libplace = smpassembly.LastIndexOf("lib");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (file.Name.Equals("System.ServiceModel.Primitives.dll", StringComparison.OrdinalIgnoreCase))
{
smpassembly = smpassembly.Remove(libplace, 3).Insert(libplace, @"runtimes\win\lib");
smassembly = path;
}
else
if (file.Name.Equals("System.Private.ServiceModel.dll", StringComparison.OrdinalIgnoreCase))
{
smpassembly = smpassembly.Remove(libplace, 3).Insert(libplace, @"runtimes/unix/lib");
smpassembly = path;
}
}
if ((string.IsNullOrEmpty(smassembly)) || (string.IsNullOrEmpty(smpassembly)))
{
ToolConsole.WriteError("Missing one or both of the paths for System.ServiceModel.Primitives and System.Private.ServiceModel");
throw new ArgumentException("Invalid smreference value");
}

try
{
Expand Down Expand Up @@ -471,8 +465,8 @@ private void LoadSMReferenceAssembly()
}
else
{
ToolConsole.WriteError("Need pass the System.ServiceModel.Primitive.dll through SM parameter");
throw new ArgumentException("Need pass the System.ServiceModel.Primitive.dll through SM parameter");
ToolConsole.WriteError("Need to pass the System.ServiceModel.Primitives.dll and the System.Private.ServiceModel.dll paths through the 'smreference' parameter.");
throw new ArgumentException("Need to pass the System.ServiceModel.Primitives.dll and the System.Private.ServiceModel.dll paths through the 'smreference' parameter.");
}
}

Expand Down
1 change: 0 additions & 1 deletion src/svcutilcore/src/dotnet-svcutil.xmlserializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,4 @@
<Message Importance="high" Text="The value of property 'PsCmd' is: $(PsCmd)" />
<Exec Command="$(PsCmd) -ExecutionPolicy UnRestricted -File $(WcfRootFolder)/src/svcutilcore/tools/scripts/UpdateSvcutilDotXmlSerializerPackage.ps1 $(PackageOutputPath)"/>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- We're building netcoreap, run on the test CLI
Reuse the same runtimeconfig that the tests use. -->
<GeneratorRuntimeConfig>$(ArtifactsBinDir)\dotnet-svcutil.xmlserializer\$(Configuration)\$(TargetFramework)\dotnet-svcutil.xmlserializer.runtimeconfig.json</GeneratorRuntimeConfig>
<GeneratorCliPath>$(DOTNET_INSTALL_DIR)</GeneratorCliPath>
<GeneratorCliPath>$(DOTNET_INSTALL_DIR)/</GeneratorCliPath>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
Expand Down Expand Up @@ -65,20 +65,27 @@
</FindInList>

<PropertyGroup>
<WcfSMOutputPath>$(ArtifactsBinDir)System.Private.ServiceModel\$(Configuration)\netstandard2.0</WcfSMOutputPath>
<ServiceModelAssemblyName>System.Private.ServiceModel.dll</ServiceModelAssemblyName>
<DotNetExe>$(GeneratorCliPath)\dotnet</DotNetExe>
<ServiceModelPrivateOutputPath>$(ArtifactsBinDir)System.Private.ServiceModel/$(Configuration)/netstandard2.0/</ServiceModelPrivateOutputPath>
<ServiceModelPrivateAssemblyName>System.Private.ServiceModel.dll</ServiceModelPrivateAssemblyName>
<ServiceModelPrimitivesOutputPath>$(ArtifactsBinDir)System.ServiceModel.Primitives.Facade/$(Configuration)/netstandard2.0/</ServiceModelPrimitivesOutputPath>
<ServiceModelPrimitivesAssemblyName>System.ServiceModel.Primitives.dll</ServiceModelPrimitivesAssemblyName>
<DotNetExe>$(GeneratorCliPath)dotnet</DotNetExe>
<DotnetSvcutilXmlSerializerAssembly>$(OutputPath)dotnet-svcutil.xmlserializer.dll</DotnetSvcutilXmlSerializerAssembly>
<InputTestAssembly>$(OutputPath)ScenarioTests.Common.Tests.dll</InputTestAssembly>
<OutputGeneratedSource>$(OutputPath)ScenarioTests.Common.Tests.XmlSerializers.cs</OutputGeneratedSource>
<CscOutputAssembly>$(OutputPath)ScenarioTests.Common.Tests.XmlSerializers.dll</CscOutputAssembly>
<ServiceModelPrivateAssembly>$(ServiceModelPrivateOutputPath)$(ServiceModelPrivateAssemblyName)</ServiceModelPrivateAssembly>
<ServiceModelPrimitivesAssembly>$(ServiceModelPrimitivesOutputPath)$(ServiceModelPrimitivesAssemblyName)</ServiceModelPrimitivesAssembly>

</PropertyGroup>
<Message Text="Running Serialization Tool" Importance="normal" />

<Message Text="Run XmlSerializer: $(DotNetExe) $(DotnetSvcutilXmlSerializerAssembly) $(InputTestAssembly) --quiet --out:$(OutputGeneratedSource) --smreference:$(WcfSMOutputPath)\$(ServiceModelAssemblyName) --reference=$(depRef)" Importance="high" />
<Message Text="$(ServiceModelAssemblyName) exists in $(WcfSMOutputPath)" Condition="Exists('$(WcfSMOutputPath)\$(ServiceModelAssemblyName)') == 'true'" Importance="high" />
<Error Text="$(ServiceModelAssemblyName) does not exist in $(WcfSMOutputPath)" Condition="Exists('$(WcfSMOutputPath)\$(ServiceModelAssemblyName)') != 'true'" />
<Exec Command="$(DotNetExe) $(DotnetSvcutilXmlSerializerAssembly) $(InputTestAssembly) --quiet --out:$(OutputGeneratedSource) --smreference:$(WcfSMOutputPath)\$(ServiceModelAssemblyName) --reference=$(depRef)" />
<Message Text="Run XmlSerializer: $(DotNetExe) $(DotnetSvcutilXmlSerializerAssembly) $(InputTestAssembly) --quiet --out:$(OutputGeneratedSource) --smreference:$(ServiceModelPrimitivesAssembly);$(ServiceModelPrivateAssembly) --reference=$(depRef)" Importance="high" />
<Message Text="$(ServiceModelPrivateAssemblyName) exists in $(ServiceModelPrivateOutputPath)" Condition="Exists('$(ServiceModelPrivateOutputPath)$(ServiceModelPrivateAssemblyName)') == 'true'" Importance="high" />
<Message Text="$(ServiceModelPrimitivesAssemblyName) exists in $(ServiceModelPrimitivesOutputPath)" Condition="Exists('$(ServiceModelPrimitivesOutputPath)$(ServiceModelPrimitivesAssemblyName)') == 'true'" Importance="high" />
<Error Text="$(ServiceModelPrivateAssemblyName) does not exist in $(ServiceModelPrivateOutputPath)" Condition="Exists('$(ServiceModelPrivateOutputPath)$(ServiceModelPrivateAssemblyName)') != 'true'" />
<Error Text="$(ServiceModelPrimitivesAssemblyName) does not exist in $(ServiceModelPrimitivesOutputPath)" Condition="Exists('$(ServiceModelPrimitivesOutputPath)$(ServiceModelPrimitivesAssemblyName)') != 'true'" />
<Exec Command="$(DotNetExe) $(DotnetSvcutilXmlSerializerAssembly) $(InputTestAssembly) --quiet --out:$(OutputGeneratedSource) --smreference:$(ServiceModelPrimitivesAssembly):$(ServiceModelPrivateAssembly) --reference=$(depRef)" />
<Warning Condition="Exists('$(OutputGeneratedSource)') != 'true'" Text="Failed to generate $(OutputGeneratedSource)"/>
<Csc Condition="Exists('$(OutputGeneratedSource)') == 'true'"
OutputAssembly="$(CscOutputAssembly)"
Expand Down

0 comments on commit eecebff

Please sign in to comment.