runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Port xsd.exe to .NET Core

Open hrushib opened this issue 10 years ago • 46 comments

We use xsd.exe to generate C# classes based on xml schema. At present there is no xsd.exe tool to generate CoreCLR compliant code and hence code generation cannot be fully automated as part of the build at the moment.

Please let us know plan/timeline for availability of the same.

hrushib avatar May 18 '16 13:05 hrushib

Related tracking issue for XmlSchema in CoreFX https://github.com/dotnet/corefx/issues/2342

/cc @piotrpMSFT @krwq @sepidehMS

joshfree avatar May 19 '16 01:05 joshfree

The code XSD.exe generates is pretty much .NET Core safe, at least in my usage. What have you seen that's not usable?

shmuelie avatar May 19 '16 05:05 shmuelie

@SamuelEnglard, AFAIK there are couple of attributes which do not exist on .NET Core which makes automating the tool harder.

@hrushib, currently I'd just add the missing attributes and treat them as no-ops so that your generated code compiles - it won't be ideal solution but should unblock you for now.

Our current plan is to bring XmlSchema back first and then proceed from there. Unfortunately I can't give you any specifics at this time :-( We currently did not have any prior requests for xsd.exe so we put it on our backlog. It's really valuable feedback to know that this is needed and being actively used as part of the build.

krwq avatar May 20 '16 00:05 krwq

@krwq Very possible. I am using it as far as feedback that it's in use 😄

shmuelie avatar May 20 '16 00:05 shmuelie

Now we have CodeDOM we do want to take a look at this for 1.2. Not immediately though.

danmoseley avatar Oct 10 '16 22:10 danmoseley

@weshaggard if we did this, how would we ship the exe? would it have to go in the shared framework?

danmoseley avatar Feb 27 '17 22:02 danmoseley

why not make it part of dotnet tooling?

shmuelie avatar Feb 27 '17 23:02 shmuelie

@weshaggard if we did this, how would we ship the exe?

The majority of the tools are part of the SDK or CLI so I would expect it to ship in one of those 2 places.

weshaggard avatar Feb 28 '17 00:02 weshaggard

I also need XmlCodeExporter to be ported to .net core (2.0). Any ETA or workaround for that? This is mostly what I use.

exporter.GetType().GetProperty
exporter.ExportTypeMapping

System.Xml.Serialization.XmlCodeExporter does not exist in .net core.

Jonathan34 avatar May 16 '17 18:05 Jonathan34

The milestone said future.

For people who been stuck 2 years and still counting. This might help but it's all in .NET framework, not .NET Core.

http://mikehadlow.blogspot.com/2007/01/writing-your-own-xsdexe.html https://github.com/codaxy/xsd2

fletchsod-developer avatar Aug 02 '17 21:08 fletchsod-developer

Not sure if this is the right place for this comment, but I have a huge xsd-generated CS file (out of all of Amazon's XSDs). It compiles fine, but when I try to serialize an object using XmlSerializer then I get a PlatformNotSupportedException, saying it can't generate the temporary assemblies. This is on .NET Core 2.0. I bet something is up with the generated CS file, if I copy relevant parts out to a new file and use that then it works fine. Can it be due to the size of the classes, or what would trigger the XmlSerializer to try to build a temporary assembly?

HakanL avatar Sep 13 '17 22:09 HakanL

I would like to be able to build a customizable XSD to C# converter, and looking at the latest recommendations, I should be using XsdDataContractImporter (together with XmlSchemaSet and CSharpCodeProvider), which is not available.

sbergen avatar Nov 15 '17 06:11 sbergen

on Oct 11, 2016 Not immediately though.

Does it mean NEVER or sometime after 2029? Please SHIP the stuff if it isn't a rocket science and doesn't require more than few hours of work. Delaying this kind of petty stuff is only letting down folks who are actually using the product, "Not immediately" even from majority's use-case doesn't explain the intensity of of hundreds of other use-cases that are relying on xsd.exe.

Will it be a dontet-cli tool?

ghost avatar Dec 30 '17 16:12 ghost

@weshaggard, @danmosemsft what is present recommendation for generating C# classes based on xml schema for CoreCLR projects built on Linux?

hrushib avatar Apr 10 '18 13:04 hrushib

@hrushib I'm using https://github.com/mganss/XmlSchemaClassGenerator successfully.

meixger avatar Apr 10 '18 16:04 meixger

@hrushib if you're doing it in automated way then we do not have any way to do that, if you're planning to generate and modify it by hand you can generate them on full framework on Windows and with minimal modification they should be usable.

krwq avatar Apr 10 '18 17:04 krwq

@krwq, I am looking forward for automation as this is expected to happen with build. We are waiting for this support for almost couple of years now. Absence of this support is pushing us to use workaround of manual updation of this file using xsd.exe and checkin for builds triggered on Linux, as full framework tool can't be used there :(.

Can you provide plans/timelines for this feature to be available on CoreCLR?

hrushib avatar Apr 13 '18 14:04 hrushib

dotnet-xscgen is released from https://github.com/mganss/XmlSchemaClassGenerator, you can reference it in your netcoreapp2.0 project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-xscgen" Version="2.0.*" />
  </ItemGroup>
</Project>

and then run it as dotnet xscgen --help in the project directory.

With dotnet 2.1's CLI, we will also be able to install it as standalone app (outside the project context): dotnet tool install dotnet-xscgen --tool-path MyTools then use it as MyTools/dotnet-xscgen.exe --help or dotnet tool install dotnet-xscgen --global and use it as dotnet xscgen --help.

ghost avatar Apr 13 '18 14:04 ghost

@hrushib we currently do not have plans for xsd.exe

krwq avatar Apr 13 '18 17:04 krwq

Does the dotnet-xscgen read in the C# model and validate the data dynamically inside the C# script instead?

If not then what DotNetCore component should I be looking for that does this with XML Schema Set, XmlReader, XmlReaderSetting, etc. stuff for this kind of XML Schema validation?

fletchsod-developer avatar Apr 24 '18 15:04 fletchsod-developer