dotnet-core/samples/xmlserializergenerator-instructions.md

41 lines
1.9 KiB
Markdown
Raw Normal View History

2017-09-22 20:13:52 +02:00
# Using Microsoft XmlSerializer Generator on .Net Core
2017-09-22 20:13:52 +02:00
Use Microsoft XmlSerializer Generator to generate Xml Serialization code for types in specified project to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.
## Prequisition:
2017-09-22 20:13:52 +02:00
The instructions assume you are using [.NET Core SDK daily builds](https://github.com/dotnet/cli#installers-and-binaries) and [.NET Core runtime daily builds](https://github.com/dotnet/core-setup#daily-builds). You can validate your .NET Core SDK version by typing `dotnet --info`.
2017-09-22 20:13:52 +02:00
## Instructions:
2017-09-22 20:13:52 +02:00
1. Create a library with `dotnet new library --name MyData`
2017-09-22 20:41:03 +02:00
1. cd into the project folder, e.g. `cd MyData`
2017-09-22 20:41:03 +02:00
1. Add a nuget.config file in the root of the project, using the following:
2017-09-22 20:33:11 +02:00
* `dotnet new nuget`
2017-09-22 20:41:03 +02:00
* Edit the new nuget.config. Remove `<clear />` and add the following line,
2017-09-22 20:13:52 +02:00
`<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />`
2017-09-22 20:33:11 +02:00
* The final file should look like [nuget.config](nuget.config).
2017-09-22 20:41:03 +02:00
4. Add reference to Microsoft.XmlSerializer.Generator package,
2017-09-22 20:41:03 +02:00
* `dotnet add package Microsoft.XmlSerializer.Generator -v 1.0.0-preview1-25718-03`
2017-09-22 20:41:03 +02:00
* Add the following lines in MyData.csproj.
```
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="1.0.0-preview1-25718-03" />
</ItemGroup>
```
2017-09-22 20:41:03 +02:00
5. Run `dotnet restore`.
2017-09-22 20:41:03 +02:00
5. Run `dotnet build`. If all succeed, a file named <AssemblyName>.XmlSerializers.dll will be generated under the output folder. You would see warnings in the output window if the serializer fail to generate.
2017-09-22 20:41:03 +02:00
5. Create a console app and add a project reference to the library. Building the app will generate serialization code for the library and the assembly will be copied to the output folder of the app.
2017-09-22 20:41:03 +02:00
5. Run `dotnet publish` to publish the app.