xsd2 icon indicating copy to clipboard operation
xsd2 copied to clipboard

Suggestion: msbuild task for automatic source generation

Open fubar-coder opened this issue 8 years ago • 6 comments

It would be nice to have a MSBuild task that creates the source code of an XSD file automatically. The following features for xsd2 would be needed:

  • [ ] Automatically detect and load includes and imports
  • [ ] Avoid duplicated processing of XSD types and elements

How should the msbuild task be configured?

fubar-coder avatar Jan 08 '17 11:01 fubar-coder

I usually invoke xsd2 from a pre-build step. If xsd files change, code is updated on the next build. That worked very well for me.

mstijak avatar Jan 08 '17 12:01 mstijak

The reason for this suggestion is, that I wanted to avoid recreation of the xsd2 output when the source file(s) didn't change to avoid unnecessary recompilation. This - just as issue #6 - is of quite low priority for me. The xsd2 tool is already usable as-is.

fubar-coder avatar Jan 08 '17 12:01 fubar-coder

That could be another flag. Skip the run if the output file is newer than the latest xsd input.

mstijak avatar Jan 08 '17 13:01 mstijak

Maybe the following PR will answer your need. https://github.com/codaxy/xsd2/pull/13

Maybe it's not perfect, but I saw in most cases, it doesn't call to xsd2 generation until file change or rebuild was requested.

I've added to rthe readme an example how should the lines in the csproj file (I guess it will be the same in msbuild file as well - the should be the same afterall...).

P.S Pay attention that I also upgraded there the .net framework (maybe I'll add .Net core support and upgrade to vs2019 one day...) as well as trasforming the csproj to the new .NET SDK format for better files and nugets management.

meirkr avatar May 25 '20 13:05 meirkr

This does look better. It's just confusing that you might end up having a dependency for a C# source file that might not exist.

fubar-coder avatar May 28 '20 11:05 fubar-coder

I don't understand your point. If the c# source doesn't exist, it will know to create the command line. If it exists and nothing was changed, since you just call build again, it won't call the command line. This is how it is done at least in visual studio configuring csproj to do this magic.

meirkr avatar May 31 '20 03:05 meirkr