Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@@ -2,9 +2,11 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<PreReleaseLabel>preview1</PreReleaseLabel>
<PackageVersion>1.0.0</PackageVersion>
<SkipValidatePackage>true</SkipValidatePackage>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AssemblyFileVersion>$(AssemblyVersion)</AssemblyFileVersion>
<AssemblyKey>Open</AssemblyKey>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>
GenerateNupkgProps;
$(BuildDependsOn)
</BuildDependsOn>
<PackageBuildPath>$(PackageOutputPath)build/</PackageBuildPath>
<PropsFilePath>$(PackageBuildPath)$(Id).props</PropsFilePath>
</PropertyGroup>
<ItemGroup>
<PackageFile Include="$(PropsFilePath)">
<TargetPath>build\</TargetPath>
</PackageFile>
</ItemGroup>
<Target Name="GenerateNupkgProps" DependsOnTargets="CalculatePackageVersion">
<PropertyGroup>
<PropsFileContents>
&lt;Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
&lt;ItemGroup&gt;
&lt;DotNetCliToolReference Include="$(Id)" Version="$(PackageVersion)" /&gt;
&lt;/ItemGroup&gt;
&lt;/Project&gt;
</PropsFileContents>
</PropertyGroup>
<MakeDir Directories="$(PackageBuildPath)"/>
<WriteLinesToFile
File="$(PropsFilePath)"
Lines="$(PropsFileContents)"
Overwrite="true" />
</Target>
</Project>

View File

@@ -4,5 +4,18 @@
<ItemGroup>
<ProjectReference Include="..\src\Microsoft.XmlSerializer.Generator.csproj" />
</ItemGroup>
<PropertyGroup>
<SkipPackageFileCheck>true</SkipPackageFileCheck>
</PropertyGroup>
<ItemGroup>
<PackageFile Include=".\build\prefercliruntime"/>
<PackageFile Include=".\build\Microsoft.XmlSerializer.Generator.targets">
<TargetPath>build\</TargetPath>
</PackageFile>
<PackageFile Include=".\build\dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json">
<TargetPath>\lib\netstandard2.0\</TargetPath>
</PackageFile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<Import Project=".\GenerateNupkgProps.targets" />
</Project>

View File

@@ -0,0 +1,27 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SerializerName>$(AssemblyName).XmlSerializers</SerializerName>
<SerializerDllImmediatePath>$(IntermediateOutputPath)$(SerializerName).dll</SerializerDllImmediatePath>
<SerializerPdbImmediatePath>$(IntermediateOutputPath)$(SerializerName).pdb</SerializerPdbImmediatePath>
<SerializerCsImmediatePath>$(IntermediateOutputPath)$(SerializerName).cs</SerializerCsImmediatePath>
<SGenWarningText>SGEN : warning SGEN1: Fail to generate the serializer for $(AssemblyName).dll. Please follow the instructions in https://go.microsoft.com/fwlink/?linkid=858594 and try again.</SGenWarningText>
</PropertyGroup>
<Target Name="GenerateSerializationAssembly" AfterTargets="Build">
<Delete Condition="Exists('$(SerializerDllImmediatePath)') == 'true'" Files="$(SerializerDllImmediatePath)" />
<Delete Condition="Exists('$(SerializerPdbImmediatePath)') == 'true'" Files="$(SerializerPdbImmediatePath)" />
<Delete Condition="Exists('$(SerializerCsImmediatePath)') == 'true'" Files="$(SerializerCsImmediatePath)" />
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec Command="dotnet Microsoft.XmlSerializer.Generator $(IntermediateOutputPath)$(AssemblyName).dll /force /quiet" ContinueOnError="true"/>
<Warning Condition="Exists('$(SerializerCsImmediatePath)') != 'true'" Text="$(SGenWarningText)" />
<Csc Condition="Exists('$(SerializerCsImmediatePath)') == 'true'" ContinueOnError="true" OutputAssembly="$(SerializerDllImmediatePath)" References="@(ReferencePath);@(IntermediateAssembly)" EmitDebugInformation="$(DebugSymbols)" Sources="$(SerializerCsImmediatePath)" TargetType="Library" ToolExe="$(CscToolExe)" ToolPath="$(CscToolPath)"/>
<Warning Condition="Exists('$(SerializerDllImmediatePath)') != 'true' And Exists('$(SerializerCsImmediatePath)') == 'true'" Text="$(SGenWarningText)"/>
<Copy Condition="Exists('$(SerializerDllImmediatePath)') == 'true'" SourceFiles="$(SerializerDllImmediatePath)" DestinationFolder="$(OutputPath)" />
</Target>
<Target Name="CleanSerializationAssembly" AfterTargets="CoreClean">
<Message Text="Cleaning serialization files..." Importance="normal"/>
<Delete Condition="Exists('$(OutputPath)\$(SerializerName).dll') == 'true'" Files="$(OutputPath)\$(SerializerName).dll" />
</Target>
<Target Name="CopySerializer" AfterTargets="PrepareForPublish">
<Copy Condition="Exists('$(OutputPath)\$(AssemblyName).XmlSerializers.dll')=='true'" SourceFiles="$(OutputPath)\$(AssemblyName).XmlSerializers.dll" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />
</Target>
</Project>

View File

@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp2.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "2.0.0"
}
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CompileDependsOn>
GenerateThisAssemblyCs;
$(CompileDependsOn)
</CompileDependsOn>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)\ThisAssembly.cs"/>
</ItemGroup>
<Target Name="GenerateThisAssemblyCs">
<PropertyGroup>
<ThisAssemblyCsContents>
using System%3B
namespace Microsoft.XmlSerializer.Generator
{
internal static class ThisAssembly
{
internal const string PackageVersion = "$(PackageVersion)"%3B
internal const string AssemblyVersion = "$(AssemblyVersion)"%3B
internal const string Version = "$(AssemblyFileVersion)"%3B
internal const string PreReleaseLabel = "$(PreReleaseLabel)"%3B
internal static string InformationalVersion
{
get
{
if (string.IsNullOrEmpty(PreReleaseLabel))
{
return PackageVersion%3B
}
else
{
return $"{PackageVersion}-{PreReleaseLabel}"%3B
}
}
}
}
}
</ThisAssemblyCsContents>
</PropertyGroup>
<!-- Write ThisAssembly.cs if this is a new version number, or it is missing -->
<WriteLinesToFile
File="$(IntermediateOutputPath)\ThisAssembly.cs"
Lines="$(ThisAssemblyCsContents)"
Overwrite="true"
Encoding="Unicode"/>
</Target>
</Project>

View File

@@ -3,11 +3,14 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{80958E8B-2FEB-4F95-83F9-825CA1ED26F8}</ProjectGuid>
<AssemblyName>Microsoft.XmlSerializer.Generator</AssemblyName>
<AssemblyName>dotnet-Microsoft.XmlSerializer.Generator</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StringResourcesPath>..\..\System.Private.Xml\src\Resources\Strings.resx</StringResourcesPath>
<DefineConstants>$(DefineConstants);XMLSERIALIZERGENERATOR</DefineConstants>
<SourceDir>..\..\System.Private.Xml\src</SourceDir>
<OutputType>Exe</OutputType>
<TargetExt>.dll</TargetExt>
<NoWarn>$(NoWarn);0169;0414;0649</NoWarn>
</PropertyGroup>
<!-- Default configurations to help VS understand the options -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
@@ -151,11 +154,6 @@
<Compile Include="System\Xml\Serialization\XmlElementAttributeExtension.cs" />
<Compile Include="System\Xml\Serialization\XmlRootAttributeExtensions.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Resources.ResourceManager" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<Import Project=".\GenerateThisAssemblyCs.targets" />
</Project>

View File

@@ -2044,7 +2044,16 @@ namespace Microsoft.XmlSerializer.Generator
else if (type == typeof(Int32))
Writer.Write(((Int32)value).ToString(null, NumberFormatInfo.InvariantInfo));
else if (type == typeof(Double))
Writer.Write(((Double)value).ToString("R", NumberFormatInfo.InvariantInfo));
{
if (double.IsNaN((Double)value))
{
Writer.Write("double.NaN");
}
else
{
Writer.Write(((Double)value).ToString("R", NumberFormatInfo.InvariantInfo));
}
}
else if (type == typeof(Boolean))
Writer.Write((bool)value ? "true" : "false");
else if ((type == typeof(Int16)) || (type == typeof(Int64)) || (type == typeof(UInt16)) || (type == typeof(UInt32)) || (type == typeof(UInt64)) || (type == typeof(Byte)) || (type == typeof(SByte)))
@@ -2058,8 +2067,15 @@ namespace Microsoft.XmlSerializer.Generator
}
else if (type == typeof(Single))
{
Writer.Write(((Single)value).ToString("R", NumberFormatInfo.InvariantInfo));
Writer.Write("f");
if (Single.IsNaN((Single)value))
{
Writer.Write("System.Single.NaN");
}
else
{
Writer.Write(((Single)value).ToString("R", NumberFormatInfo.InvariantInfo));
Writer.Write("f");
}
}
else if (type == typeof(Decimal))
{

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="Microsoft.XmlSerializer.Generator">
<Assembly Name="Microsoft.XmlSerializer.Generator">
<Namespace Name="Microsoft.XmlSerializer.Generator">
<!-- XmlQualifiedName is well known to the serializers and must not be explicitly specified to sg.exe -->
<Type Name="XmlQualifiedName" DataContractSerializer="Excluded" DataContractJsonSerializer="Excluded"/>
</Namespace>
</Assembly>
</Library>
</Directives>

View File

@@ -12,13 +12,12 @@ using System.Threading;
namespace Microsoft.XmlSerializer.Generator
{
public class Sgen
internal class Sgen
{
public static int Main(string[] args)
{
Sgen sgen = new Sgen();
sgen.Run(args);
return 0;
return sgen.Run(args);
}
private int Run(string[] args)
@@ -29,18 +28,21 @@ namespace Microsoft.XmlSerializer.Generator
var errs = new ArrayList();
bool force = false;
bool proxyOnly = false;
bool disableRun = true;
bool noLogo = false;
bool parsableErrors = false;
bool silent = false;
bool warnings = false;
try
{
for (int i = 0; i < args.Length; i++)
{
bool argument = false;
string arg = args[i];
string value = string.Empty;
if (arg.StartsWith("/") || arg.StartsWith("-"))
{
argument = true;
int colonPos = arg.IndexOf(":");
if (colonPos != -1)
{
@@ -49,22 +51,15 @@ namespace Microsoft.XmlSerializer.Generator
}
}
string originalArg = arg;
arg = arg.ToLower(CultureInfo.InvariantCulture);
if (ArgumentMatch(arg, "?") || ArgumentMatch(arg, "help"))
{
WriteHeader();
WriteHelp();
return 0;
}
else if (!argument && (arg.EndsWith(".dll") || arg.EndsWith(".exe")))
{
if (assembly != null)
{
errs.Add(SR.Format(SR.ErrInvalidArgument, "/assembly", arg));
}
assembly = arg;
}
else if (ArgumentMatch(arg, "force"))
{
force = true;
@@ -86,18 +81,63 @@ namespace Microsoft.XmlSerializer.Generator
{
types.Add(value);
}
else if (ArgumentMatch(arg, "assembly"))
{
if (assembly != null)
{
errs.Add(SR.Format(SR.ErrInvalidArgument, "/assembly", arg));
}
assembly = value;
}
else if (ArgumentMatch(arg, "quiet"))
{
disableRun = false;
}
else if (ArgumentMatch(arg, "nologo"))
{
noLogo = true;
}
else if (ArgumentMatch(arg, "silent"))
{
silent = true;
}
else if (ArgumentMatch(arg, "parsableerrors"))
{
parsableErrors = true;
}
else if (ArgumentMatch(arg, "verbose"))
{
warnings = true;
}
else
{
errs.Add(SR.Format(SR.ErrInvalidArgument, arg));
continue;
if (arg.EndsWith(".dll") || arg.EndsWith(".exe"))
{
if (assembly != null)
{
errs.Add(SR.Format(SR.ErrInvalidArgument, "/assembly", arg));
}
assembly = originalArg;
}
else
{
errs.Add(SR.Format(SR.ErrInvalidArgument, arg));
}
}
}
if (!noLogo)
{
WriteHeader();
}
if (errs.Count > 0)
{
foreach (string err in errs)
{
Console.Error.WriteLine(FormatMessage(true, SR.Format(SR.Warning, err)));
Console.Error.WriteLine(FormatMessage(parsableErrors, true, SR.Format(SR.Warning, err)));
}
}
@@ -105,14 +145,21 @@ namespace Microsoft.XmlSerializer.Generator
{
if (assembly == null)
{
Console.Error.WriteLine(FormatMessage(false, SR.Format(SR.ErrMissingRequiredArgument, SR.Format(SR.ErrAssembly, "assembly"))));
Console.Error.WriteLine(FormatMessage(parsableErrors, false, SR.Format(SR.ErrMissingRequiredArgument, SR.Format(SR.ErrAssembly, "assembly"))));
}
WriteHelp();
return 0;
}
GenerateFile(types, assembly, proxyOnly, force, codePath);
if(disableRun)
{
Console.WriteLine("This tool is not intended to be used directly.");
Console.WriteLine("Please refer to https://github.com/dotnet/core/blob/master/samples/xmlserializergenerator-instructions.md on how to use it.");
return 0;
}
GenerateFile(types, assembly, proxyOnly, silent, warnings, force, codePath, parsableErrors);
}
catch (Exception e)
{
@@ -121,13 +168,14 @@ namespace Microsoft.XmlSerializer.Generator
throw;
}
WriteError(e, parsableErrors);
return 1;
}
return 0;
}
private void GenerateFile(List<string> typeNames, string assemblyName, bool proxyOnly, bool force, string outputDirectory)
private void GenerateFile(List<string> typeNames, string assemblyName, bool proxyOnly, bool silent, bool warnings, bool force, string outputDirectory, bool parsableerrors)
{
Assembly assembly = LoadAssembly(assemblyName, true);
Type[] types;
@@ -161,7 +209,7 @@ namespace Microsoft.XmlSerializer.Generator
Type type = assembly.GetType(typeName);
if (type == null)
{
Console.Error.WriteLine(FormatMessage(false, SR.Format(SR.ErrorDetails, SR.Format(SR.ErrLoadType, typeName, assemblyName))));
Console.Error.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrorDetails, SR.Format(SR.ErrLoadType, typeName, assemblyName))));
}
types[typeIndex++] = type;
@@ -197,7 +245,7 @@ namespace Microsoft.XmlSerializer.Generator
if (!proxyOnly)
{
ImportType(type, mappings, importedTypes, importer);
ImportType(type, mappings, importedTypes, warnings, importer, parsableerrors);
}
}
@@ -227,7 +275,8 @@ namespace Microsoft.XmlSerializer.Generator
throw new ArgumentException(SR.Format(SR.ErrDirectoryNotExists, codePath, outputDirectory));
}
bool success;
bool success = false;
bool toDeleteFile = true;
try
{
@@ -243,19 +292,34 @@ namespace Microsoft.XmlSerializer.Generator
}
catch (UnauthorizedAccessException)
{
toDeleteFile = false;
throw new UnauthorizedAccessException(SR.Format(SR.DirectoryAccessDenied, outputDirectory));
}
finally
{
if (!success && toDeleteFile && File.Exists(codePath))
{
File.Delete(codePath);
}
}
if (success)
{
Console.Out.WriteLine(SR.Format(SR.InfoAssemblyName, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedAssembly, assembly.Location, codePath));
if (!silent)
{
Console.Out.WriteLine(SR.Format(SR.InfoFileName, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedFile, assembly.Location, codePath));
}
}
else
{
Console.Out.WriteLine(FormatMessage(false, SR.Format(SR.ErrGenerationFailed, assembly.Location)));
Console.Out.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrGenerationFailed, assembly.Location)));
}
}
else
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoNoSerializableTypes, assembly.Location)));
}
}
// assumes all same case.
@@ -270,7 +334,7 @@ namespace Microsoft.XmlSerializer.Generator
return (arg == formal || (arg.Length == 1 && arg[0] == formal[0]));
}
private void ImportType(Type type, ArrayList mappings, ArrayList importedTypes, XmlReflectionImporter importer)
private void ImportType(Type type, ArrayList mappings, ArrayList importedTypes, bool verbose, XmlReflectionImporter importer, bool parsableerrors)
{
XmlTypeMapping xmlTypeMapping = null;
var localImporter = new XmlReflectionImporter();
@@ -284,10 +348,33 @@ namespace Microsoft.XmlSerializer.Generator
{
throw;
}
if (verbose)
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoIgnoreType, type.FullName)));
WriteWarning(e, parsableerrors);
}
return;
}
if (xmlTypeMapping != null)
{
if (xmlTypeMapping.Mapping != null && xmlTypeMapping.Mapping is StructMapping)
{
foreach (MemberMapping memberMapping in ((StructMapping)xmlTypeMapping.Mapping).Members)
{
MemberInfo memberInfo = memberMapping.MemberInfo;
if (memberInfo != null && memberInfo.MemberType == MemberTypes.Property)
{
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
if (propertyInfo != null && (propertyInfo.SetMethod == null || !propertyInfo.SetMethod.IsPublic))
{
return;
}
}
}
}
xmlTypeMapping = importer.ImportTypeMapping(type);
mappings.Add(xmlTypeMapping);
importedTypes.Add(type);
@@ -299,30 +386,67 @@ namespace Microsoft.XmlSerializer.Generator
Assembly assembly = null;
string path = Path.GetFullPath(assemblyName);
assembly = Assembly.LoadFile(path);
if (assembly == null)
{
throw new InvalidOperationException(SR.Format(SR.ErrLoadAssembly, assemblyName));
}
return assembly;
}
private void WriteHeader()
{
// do not localize Copyright header
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "[Microsoft (R) .NET Framework, Version {0}]", TempAssembly.ThisAssembly.InformationalVersion));
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "[Microsoft (R) .NET Core Xml Serialization Generation Utility, Version {0}]", ThisAssembly.InformationalVersion));
Console.WriteLine("Copyright (C) Microsoft Corporation. All rights reserved.");
}
void WriteHelp()
private void WriteHelp()
{
//TBD
Console.WriteLine("In Development");
Console.Out.WriteLine(SR.Format(SR.HelpDescription));
Console.Out.WriteLine(SR.Format(SR.HelpUsage, this.GetType().Assembly.GetName().Name));
Console.Out.WriteLine(SR.Format(SR.HelpDevOptions));
Console.Out.WriteLine(SR.Format(SR.HelpAssembly, "/assembly:", "/a:"));
Console.Out.WriteLine(SR.Format(SR.HelpType, "/type:", "/t:"));
Console.Out.WriteLine(SR.Format(SR.HelpProxy, "/proxytypes", "/p"));
Console.Out.WriteLine(SR.Format(SR.HelpForce, "/force", "/f"));
Console.Out.WriteLine(SR.Format(SR.HelpOut, "/out:", "/o:"));
Console.Out.WriteLine(SR.Format(SR.HelpMiscOptions));
Console.Out.WriteLine(SR.Format(SR.HelpHelp, "/?", "/help"));
}
private static string FormatMessage(bool warning, string message)
private static string FormatMessage(bool parsableerrors, bool warning, string message)
{
return FormatMessage(warning, "SGEN1", message);
return FormatMessage(parsableerrors, warning, "SGEN1", message);
}
private static string FormatMessage(bool warning, string code, string message)
private static string FormatMessage(bool parsableerrors, bool warning, string code, string message)
{
if (!parsableerrors)
{
return message;
}
return "SGEN: " + (warning ? "warning " : "error ") + code + ": " + message;
}
private static void WriteError(Exception e, bool parsableerrors)
{
Console.Error.WriteLine(FormatMessage(parsableerrors, false, e.Message));
if (e.InnerException != null)
{
WriteError(e.InnerException, parsableerrors);
}
}
static void WriteWarning(Exception e, bool parsableerrors)
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, e.Message));
if (e.InnerException != null)
{
WriteWarning(e.InnerException, parsableerrors);
}
}
}
}

View File

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Xunit;
public static partial class XmlSerializerTests
{
//This is a dummy test that runs on all platform. It is to make sure we have at least one test running in UWP platform, which will exclude all other SGENTESTS.
[Fact]
public static void AlwaysPassTest()
{
Assert.True(true);
}
}

View File

@@ -3,6 +3,8 @@
<PropertyGroup>
<BuildConfigurations>
netstandard;
uap;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -3,15 +3,89 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{0D1E2954-A5C7-4B8C-932A-31EB4A96A737}</ProjectGuid>
<DefineConstants>$(DefineConstants);XMLSERIALIZERGENERATORTESTS</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<SkipTestsOnPlatform Condition="'$(TargetGroup)' == 'uap' OR '$(ArchGroup)' == 'arm' OR '$(ArchGroup)' == 'arm64' OR '$(ArchGroup)' == 'armel'">true</SkipTestsOnPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<!-- We're building netcoreap, run on the test CLI
Reuse the same runtimeconfig that the tests use. -->
<GeneratorRuntimeConfig>$(ToolsDir)xunit.console.netcore.runtimeconfig.json</GeneratorRuntimeConfig>
<GeneratorCliPath>$(TestHostRootPath)</GeneratorCliPath>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' != 'netcoreapp'">
<!-- We're building some non-netcoreapp target, run on the Tools CLI.
Reuse the same runtimeconfig used by CSC. -->
<GeneratorRuntimeConfig>$(ToolsDir)csc.runtimeconfig.json</GeneratorRuntimeConfig>
<GeneratorCliPath>$(ToolsDir)dotnetcli/</GeneratorCliPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<ItemGroup Condition=" '$(SkipTestsOnPlatform)' != 'true' ">
<Compile Include=".\SGenTests.cs" />
<Compile Include="$(TestSourceFolder)..\..\System.Runtime.Serialization.Xml\tests\Utils.cs" />
<Compile Include="$(TestSourceFolder)..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.cs" />
<Compile Include="$(TestSourceFolder)..\..\System.Private.Xml\tests\XmlSerializer\XmlSerializerTests.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include=".\SGenTests.cs" />
<Compile Include=".\AlwaysPassTest.cs" />
<Content Include="$(GeneratorRuntimeConfig)">
<!-- Rename it to match the Generator application name -->
<Link>dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ReferenceFromRuntime Include="dotnet-Microsoft.XmlSerializer.Generator">
<!-- Copy this to our test output directory and run from there.
This is required so that we can stage the application with a custom runtimeconfig that lets it run on the test shared framework. -->
<Private>true</Private>
</ReferenceFromRuntime>
</ItemGroup>
<!-- This target runs before binplacing as it needs to provide a test assembly to binplace, and depends on CopyFilesToOutputDirectory
so that the Generator app dll and runtimeconfig will be copied to the OutputPath -->
<Target Name="GenerateSerializationAssembly" DependsOnTargets="CopyFilesToOutputDirectory" BeforeTargets="GetBinPlaceItems" Condition=" '$(SkipTestsOnPlatform)' != 'true' " >
<PropertyGroup>
<SerializerName>$(AssemblyName).XmlSerializers</SerializerName>
</PropertyGroup>
<Message Text="Running Serialization Tool" Importance="normal" />
<Exec Command="$(GeneratorCliPath)dotnet $(OutputPath)dotnet-Microsoft.XmlSerializer.Generator.dll $(OutputPath)Microsoft.XmlSerializer.Generator.Tests.dll /force /quiet" />
<Warning Condition="Exists('$(OutputPath)$(SerializerName).cs') != 'true'" Text="Fail to generate $(OutputPath)$(SerializerName).cs"/>
<Csc Condition="Exists('$(OutputPath)$(SerializerName).cs') == 'true' AND '$(MSBuildRuntimeType)' != 'core'"
OutputAssembly="$(OutputPath)$(SerializerName).dll"
References="@(ReferencePath);@(IntermediateAssembly)"
EmitDebugInformation="$(DebugSymbols)"
DebugType="$(DebugType)"
Sources="$(OutputPath)$(SerializerName).cs"
TargetType="Library"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)"
DisabledWarnings="$(NoWarn), 219"
UseSharedCompilation="true" />
<!-- when building on core CSC requires the OverrideToolHost parameter, but this is not supported by desktop csc -->
<Csc Condition="Exists('$(OutputPath)$(SerializerName).cs') == 'true' AND '$(MSBuildRuntimeType)' == 'core'"
OutputAssembly="$(OutputPath)$(SerializerName).dll"
References="@(ReferencePath);@(IntermediateAssembly)"
EmitDebugInformation="$(DebugSymbols)"
DebugType="$(DebugType)"
Sources="$(OutputPath)$(SerializerName).cs"
TargetType="Library"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)"
OverrideToolHost="$(OverrideToolHost)"
DisabledWarnings="$(NoWarn), 219"
UseSharedCompilation="true" />
<Warning Condition="Exists('$(OutputPath)$(SerializerName).dll') != 'true'" Text="Fail to generate $(OutputPath)$(SerializerName).dll"/>
<ProjectReference Include="..\src\Microsoft.XmlSerializer.Generator.csproj" />
</ItemGroup>
<ItemGroup>
<!-- Include the Serializer in ReferenceCopyLocalPaths so that it will be binplaced -->
<ReferenceCopyLocalPaths Include="$(OutputPath)$(SerializerName).dll" />
</ItemGroup>
</Target>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -5,16 +5,24 @@
using Xunit;
using Microsoft.XmlSerializer.Generator;
using System.IO;
using System;
using System.Reflection;
namespace Microsoft.XmlSerializer.Generator.Tests
{
public static class SgenTests
{
[Fact]
public static void BasicTest()
public static void SgenCommandTest()
{
int n = Sgen.Main(null);
string codefile = "Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs";
var type = Type.GetType("Microsoft.XmlSerializer.Generator.Sgen, dotnet-Microsoft.XmlSerializer.Generator");
MethodInfo md = type.GetMethod("Main", BindingFlags.Static | BindingFlags.Public);
string[] args = new string[] { "Microsoft.XmlSerializer.Generator.Tests.dll", "/force", "/quiet" };
int n = (int)md.Invoke(null, new object[] { args });
Assert.Equal(0, n);
Assert.True(File.Exists(codefile), string.Format("Fail to generate {0}.", codefile));
}
}
}