LinqToXsdCore 3.0.0.5

.NET Core 2.1
There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global LinqToXsdCore --version 3.0.0.5
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local LinqToXsdCore --version 3.0.0.5
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=LinqToXsdCore&version=3.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package LinqToXsdCore --version 3.0.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

LinqToXsd

This project forms the command-line interface utility used to generate C# code that represents the structure of an XML document that conforms to an W3C XML Schema (XSD).

Most of the logic for reading an XSD is coded in the XObjectsCore project, but logic that is specific to an individual XSD (like custom types and elements), is generated as C# code using the CodeDOM provider (also inside XObjectsCore) that is invoked via this CLI tool.

The code this tool generates has a dependency on namespaces defined in the XObjectsCore library. You can add a reference to that library via nuget here: https://www.nuget.org/packages/XObjectsCore

Don't add this project as a dependency to your shipping libraries or app - depend on the code it generates, and the XObjectsCore library instead.

This project adds additional features from the old CLI tool (the XObjectsGenerator project is the legacy CLI), like generating .config files with default values from an existing XSD and generating code from multiple XSD's and multiple .config files.

Installation

This tool is published as a global .NET tool here: https://www.nuget.org/packages/LinqToXsdCore. Install it using

dotnet tool install LinqToXsdCore -g

After that, you can use the tool globally via the command 'LinqToXsd' at a console (cmd or powershell).

Using LinqToXsd to generate code

Before generating code, create an example configuration file from your XSD (this will allow you to customize how XML namespaces map to .NET CLR namepsaces).

linqtoxsd config -e wss.xsd

Currently, as this is a port of the LinqToXsd project, some configuration elements are not documented but for some reason or another are processed and interpreted in source code. But the gist of what you need as a developer is to pay attention to the <Namespaces /> element.

Under that element, it will create default namepsace mappings similar to the following example:

<Namespaces>
  <Namespace Schema="http://schemas.microsoft.com/sharepoint/" Clr="schemas.microsoft.com.sharepoint" />
</Namespaces>

The XML namespace http://schemas.microsoft.com/sharepoint/ becomes: schemas.microsoft.com.sharepoint in the generated C# code. And obviously now that you have a configuration file you can change the default values to something more suitable for you.

To use your new configuraton file to generate code:

linqtoxsd gen wss.xsd -c .\wss.xsd.config

It will output code to 'file.xsd.cs', or in this case 'wss.xsd.cs'.

Regenerating code

You can also add a pre-build event in your Visual Studio project definition, invoking the linqtoxsd tool to regenerate code every time you build your solution:

linqtoxsd gen "$(ProjectDir)wss.xsd" -c "$(ProjectDir)wss.xsd.config"

In the above example, the strings beginning with $() are MSBuild macros.

Help for other functions

There's some other miscellaneous functions in the CLI tool that may be helpful to you, and be used to exert finer control over code output. To view the help screen for this tool:

linqtoxsd help

To view help for a specific verb:

linqtoxsd <verb> --help

To view help on configuration file generation:

linqtoxsd config --help

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
3.3.2 122 3/30/2022
3.3.1 47 3/29/2022
3.3.0 43 3/28/2022
3.2.1 610 7/3/2021
3.2.0 256 2/15/2021
3.1.0 520 5/3/2020
3.0.1 390 3/15/2020
3.0.0.12 249 3/11/2020
3.0.0.11 290 3/5/2020
3.0.0.10 348 2/14/2020
3.0.0.9 274 1/18/2020
3.0.0.8 302 10/27/2019
3.0.0.7 305 10/1/2019
3.0.0.6 310 9/27/2019
3.0.0.5 324 8/20/2019
3.0.0.4 374 6/7/2019
3.0.0.3-beta 321 5/15/2019