Visual C# Developer Center >
Visual C# Forums
>
Visual C# IDE
>
InvaidProjectFileException.. hw can i solve it ?
InvaidProjectFileException.. hw can i solve it ?
- hi all,
i m reading one project file and thn i m reading its property as xml string . i m chaning the xml attrubute valu and thn i wann to assgin this changed property xml string again to my projct . pls check the code . bt i m getting exception tat " InvaidProjectFileException ==> The project file must be opened in the Visual Studio IDE and converted to the latest version before it can be built by MSBuild."
is thr way out ??
<br/> Project Proj = new Project(); Proj.Load(this.Projct); string ProjecXml = Proj.Xml; XmlDocument xd = new XmlDocument(); xd.Load(this.Projct); xd.LoadXml(xd.InnerXml); XmlElement root = xd.DocumentElement; while (xReader.Read()) { switch (xReader.NodeType) { case XmlNodeType.Element: if (xReader.HasAttributes) { for (int i = 0; i < xReader.AttributeCount; i++) { root.SetAttribute(xReader.Name, "newvalu"); } } } } Proj.LoadXml(xd.inerxml); // i mgetting exception here
Answers
- Firstly this is the wrong way to edit project files. I don't understand what you're trying to accomplish so I can't provide a better alternative but mucking directly with the XML is a bad idea. The Project class exposes methods to add and remove items and to set property values. That should be sufficient for most things.
As for your code you're changing all attributes to newvalu. That's guaranteed to break the project file because the project file read assumes that some attributes are integers, others date, others guids, etc. If you change everything to a string value then conversions to the other types will fail and, hence, an exception occurs.
Michael Taylor - 11/2/09
http://p3net.mvps.org- Marked As Answer byaniruddha84 Tuesday, November 03, 2009 10:48 AM
- hi,
yes now i m using the
projct.setproperty("propertyname","Property Value");
instid of this line ... root.SetAttribute(xReader.Name, "newvalu");
i m able to change property.
thn again i m loading this changed property to projct.Loadxml(projct.xml);
bt its nt saving my property permently . so whn once agin i run my code i m getting that changed property as not matched property .
can anyone help me out
hw can i change project property and save it- Marked As Answer byaniruddha84 Tuesday, November 03, 2009 10:48 AM
All Replies
- Firstly this is the wrong way to edit project files. I don't understand what you're trying to accomplish so I can't provide a better alternative but mucking directly with the XML is a bad idea. The Project class exposes methods to add and remove items and to set property values. That should be sufficient for most things.
As for your code you're changing all attributes to newvalu. That's guaranteed to break the project file because the project file read assumes that some attributes are integers, others date, others guids, etc. If you change everything to a string value then conversions to the other types will fail and, hence, an exception occurs.
Michael Taylor - 11/2/09
http://p3net.mvps.org- Marked As Answer byaniruddha84 Tuesday, November 03, 2009 10:48 AM
- hi,
yes now i m using the
projct.setproperty("propertyname","Property Value");
instid of this line ... root.SetAttribute(xReader.Name, "newvalu");
i m able to change property.
thn again i m loading this changed property to projct.Loadxml(projct.xml);
bt its nt saving my property permently . so whn once agin i run my code i m getting that changed property as not matched property .
can anyone help me out
hw can i change project property and save it- Marked As Answer byaniruddha84 Tuesday, November 03, 2009 10:48 AM
- Project.Save will save the project file back out.
Michael Taylor - 11/3/09
http://p3net.mvps.org


