codaxy / xsd2

Improved version of xsd.exe
MIT License
34 stars 21 forks source link

Suggestion: msbuild task for automatic source generation #7

Open fubar-coder opened 7 years ago

fubar-coder commented 7 years ago

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:

How should the msbuild task be configured?

mstijak commented 7 years ago

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.

fubar-coder commented 7 years ago

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.

mstijak commented 7 years ago

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

meirkr commented 4 years ago

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.

fubar-coder commented 4 years ago

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.

meirkr commented 4 years ago

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.