LinqToXsdCore 3.0.0.1-beta
See the version list below for details.
dotnet add package LinqToXsdCore --version 3.0.0.1-beta
NuGet\Install-Package LinqToXsdCore -Version 3.0.0.1-beta
<PackageReference Include="LinqToXsdCore" Version="3.0.0.1-beta" />
paket add LinqToXsdCore --version 3.0.0.1-beta
#r "nuget: LinqToXsdCore, 3.0.0.1-beta"
// Install LinqToXsdCore as a Cake Addin #addin nuget:?package=LinqToXsdCore&version=3.0.0.1-beta&prerelease // Install LinqToXsdCore as a Cake Tool #tool nuget:?package=LinqToXsdCore&version=3.0.0.1-beta&prerelease
LinqToXsdCore
Introduction
This is a port of LinqToXsd to .NET Core. Most of what was in the original project is here, but built for .NET Core! For people who specifically need .NET 4/3.5 support, please use the original code on the codeplex archive.
Wait so what is this?
LinqToXsd was first released back in 2009, and it was billed then as a way of 'provding .NET developers with support for typed XML programming...LINQ to XSD enhances the existing LINQ to XML technology'.
Basically LinqToXsd generates code at design time, which models the structure of a XML document according, according to a W3C XML Schema (XSD). This allows a developer to program against the generated code, using strong types, where classes represents element definitions and class properties (i.e. getters and setters) represent attributes on XML elements.
Consider this XML:
<?xml version="1.0" encoding="UTF-8"?>
<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./Purchase Order.xsd">
<general>
<poNum>poNum0</poNum>
<poDate>2006-05-04</poDate>
</general>
<order>
<companyName>companyName0</companyName>
<address>address0</address>
<city>city0</city>
<stateProv>stateProv0</stateProv>
<zipCode>zipCode0</zipCode>
<country>country0</country>
<phone>phone0</phone>
<fax>fax0</fax>
<contactName>contactName0</contactName>
</order>
</purchaseOrder>
To get the <city>
element with regular LINQ to XML code, you'd write:
var purchaseOrderDoc = XDocument.Load("po.xml");
var orderElement = purchaseOrderDoc.Descendants(XName.Get("order"));
var cityElement = orderElement.Descendants(XName.Get("city"));
With LinqToXsd you would write:
var po = purchaseOrder.Load("po.xml");
var order = po.order;
var city = order.city;
The amount of code one writes to traverse an XML document is reduced as LinqToXsd builds a strongly-typed model for you through its code generator. This makes LinqToXsd incredibly helpful when dealing and handling XML data, especially if it comes with an accompanying XSD file, as most XML formats tend to do. Even if there isn't a native XSD, you can just infer an XSD from an existing XML file and speed up your development that way.
Things not supported
No assembly generation - due to a dependency on CodeDOM, no direct code-generation (making .DLL's) is supported. CodeDOM for .NET Core does not support this on any platform (even Windows)
The Visual Studio targets project is in the repo, but is not properly ported over to .NET core. The VS target (that allows feeding an XSD in a solution or project to a custom build action) is planned to be ported later on.
Mini-instructions
There are two CLI apps present in this repo: LinqToXsd and XObjectsGenerator. Both are .NET core console apps:
- XObjectsGenerator is a straight-up copy and paste of the legacy CLI tool. Use this if you have custom build events that use its syntax.
- LinqToXsd uses a custom CLI parser. It provides a better interface for functions that are explicitly supported.
- Both of these tools target .NET Core 2.0.
To invoke either of the CLI tools:
dotnet .\XObjectsGenerator.dll
or
dotnet .\LinqToXsd.dll
Pre-release Nuget package
To use the pre-release Nuget package (https://www.nuget.org/packages/LinqToXsdCore/3.0.0.1-beta), install LinqToXsdCore (it has a dependency on XObjectsCore and will install that as well). Then use the CLI tool generate a configuration file for your XSD files first before generating code.
After that, and editing the config file so namespaces map properly to the CLR, add an invocation to the CLI tool as a pre-build event into your project:
Visual Studio 2017+
dotnet %userprofile%\.nuget\packages\LinqToXsdCore\lib\netcoreapp2.0\XObjectsCore.dll <commandlineargs>
If you're using Visual Studio 2017 or above you won't have a solution-scoped packages folder. It gets downloaded to your user profile nuget repository.
Visual Studio 2015 and below:
dotnet $(SolutionDir)packages\LinqToXsdCore\lib\netcoreapp2.0\XObjectsCore.dll <commandlineargs>
Using LinqToXsd
We recommend you use this tool to generate code. To generate code from an XSD (will output to filename.xsd.cs):
dotnet LinqToXsd.dll gen "SharePoint2010\wss.xsd"
To generate code from an XSD with a configuration file (that maps XML namespaces to CLR namespace):
dotnet LinqToXsd.dll gen "SharePoint2010\wss.xsd" --Config "SharePoint2010\wss.xsd.config"
License
This is licensed under the same license that the original LinqToXsd project was licensed under, which is the Microsoft Public License (MS-PL): https://opensource.org/licenses/MS-PL
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- CommandLineParser (>= 2.4.3)
- Microsoft.NETCore.App (>= 2.0.0)
- XObjectsCore (>= 3.0.0-beta)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.4.7 | 322 | 7/19/2024 |
3.4.6 | 2,458 | 2/13/2024 |
3.4.5 | 223 | 2/6/2024 |
3.4.4 | 235 | 1/29/2024 |
3.4.3 | 212 | 1/24/2024 |
3.4.2 | 599 | 10/2/2023 |
3.4.1 | 278 | 9/16/2023 |
3.4.0 | 364 | 7/3/2023 |
3.3.3 | 600 | 1/6/2023 |
3.3.2 | 828 | 3/30/2022 |
3.3.1 | 449 | 3/29/2022 |
3.3.0 | 512 | 3/28/2022 |
3.2.1 | 1,023 | 7/3/2021 |
3.2.0 | 523 | 2/15/2021 |
3.1.0 | 737 | 5/3/2020 |
3.0.1 | 665 | 3/15/2020 |
3.0.0.12 | 501 | 3/11/2020 |
3.0.0.11 | 558 | 3/5/2020 |
3.0.0.10 | 591 | 2/14/2020 |
3.0.0.9 | 563 | 1/18/2020 |
3.0.0.8 | 610 | 10/27/2019 |
3.0.0.7 | 645 | 10/1/2019 |
3.0.0.6 | 610 | 9/27/2019 |
3.0.0.5 | 602 | 8/20/2019 |
3.0.0.4 | 644 | 6/7/2019 |
3.0.0.3-beta | 426 | 5/15/2019 |