-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlSerializerGenerator.targets
41 lines (40 loc) · 2.22 KB
/
XmlSerializerGenerator.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<Project>
<UsingTask TaskName="FixXmlSerializer"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFile ParameterType="System.String" Required="true" />
<RootNamespace ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var input = File.ReadAllText(InputFile);
input =
"// <auto-generated> This file has been auto generated. </auto-generated>\n" +
"#nullable disable\n" +
"#pragma warning disable IL2026\n" +
"#pragma warning disable IL2046\n" +
"#pragma warning disable CS0219\n" +
input.Replace("namespace Microsoft.Xml.Serialization.GeneratedAssembly {", $"namespace {RootNamespace} {{");
File.WriteAllText(InputFile, input);
]]>
</Code>
</Task>
</UsingTask>
<ItemGroup>
<PackageReference Include="Microsoft.XmlSerializer.Generator" Version="8.0.0" GeneratePathProperty="true" ExcludeAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)GeneratedXmlSerializer.XmlSerializers.cs" />
</ItemGroup>
<Target Name="GenerateXmlSerializer" DependsOnTargets="ResolveReferences" Inputs="@(SgenCompile)" Outputs="$(IntermediateOutputPath)GeneratedXmlSerializer.XmlSerializers.cs" BeforeTargets="CoreCompile">
<PropertyGroup>
<SgenRootNamespace Condition="'$(SgenRootNamespace)' == ''">$(RootNamespace)</SgenRootNamespace>
</PropertyGroup>
<Csc Sources="@(SgenCompile)" References="@(Reference)" TargetType="library" OutputAssembly="$(IntermediateOutputPath)GeneratedXmlSerializer.dll" Nullable="$(Nullable)" />
<Exec Command=""$(NetCoreRoot)dotnet" "$(PkgMicrosoft_XmlSerializer_Generator)/lib/netstandard2.0/dotnet-Microsoft.XmlSerializer.Generator.dll" "$(IntermediateOutputPath)GeneratedXmlSerializer.dll" --force --quiet @(SgenOptions -> '"%(Identity)"', ' ')" />
<FixXmlSerializer InputFile="$(IntermediateOutputPath)GeneratedXmlSerializer.XmlSerializers.cs" RootNamespace="$(SgenRootNamespace)" />
</Target>
</Project>