C# Project has auto generated classes, but what auto generated them?
I am working on a project that I was the original developer on, but over the last couple of years two other developers have maintained and upgraded the project.
There are now some class files inside with the following at the top:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=2.0.50727.1432.
//
Any id开发者_如何转开发ea what could have generated these files? There are some issues inside one of them I want to clean up, but it says the changes might be overwritten.
It's the XML Schema Definition Tool. What do you want to clean up?
Note that one of the operations performed by Xsd.exe is "XSD to classes", which is what generated your class files in question:
XSD to Classes
Generates runtime classes from an XSD schema file. The generated classes can be used in conjunction with System.Xml.Serialization.XmlSerializer to read and write XML code that follows the schema.
You should be able to change the source XSD files, then re-run Xsd.exe in order to change the output while maintaining compatibility with the exe itself.
XSD.exe generated them. It is a tool in the .Net SDK that takes an XSD schema and generates serializable classes that match the schema.
Check the "Pre-Build" step in the properties of the project. I bet you will find a call to xsd.exe. If not, it might be a directive defined in the .csproj file (MSBuild). Do you know for sure that they are being generated at runtime? Or were they generated by hand and checked in?
If I remember properly, the classes generated are partials, so you can add functionality via partial classes... but you can't modify the classes themselves if they are generated at build time.
If you want to change the classes, you need to modify the XSD file that the app is using to generate the file.
精彩评论