My converted VB project did not seem to link designer (.designer.vb) and embedded resource files (.resx) correctly to
their owner forms.
Some of these files are not nested properly underneath their appropriate parent after linking or upgrades.
The root of the problem is in the .vbproj file where a DependentUpon node is missing.
Use the following C# class will fix these problems in the project (vbproj) file.
Please back up your vbproj file before using this code.
using System;
using System.Xml;
using System.Xml.XPath;
public class VBDepFix
{
XmlDocument _doc;
public VBDepFix(string path)
{
//path is .VBProj path
//this code will overwrite existing vbproj
//so PLEASE BACK UP YOUR .vbproj FILE BEFORE USING THIS
_doc=new XmlDocument();
_doc.Load(path);
fixEmbeddedResources();
fixDesigners();
_doc.Save(path);
}
private void fixEmbeddedResources()
{
XmlNodeList nodeList = _doc.GetElementsByTagName("EmbeddedResource");
foreach (XmlNode nd in nodeList)
fixDependentNode(nd);
}
private void fixDesigners()
{
XmlNodeList nodeList = _doc.GetElementsByTagName("Compile");
foreach (XmlNode nd in nodeList)
{
//this assumes only Designers can have .Designer.string but probaby correct.
if( nd.Attributes.GetNamedItem("Include").Value.IndexOf(".Designer.")>0)
fixDependentNode(nd);
}
}
private void fixDependentNode(XmlNode ndParent)
{
foreach (XmlNode nd in ndParent.ChildNodes)
{
if (nd.Name=="DependentUpon")
return;
}
addDependencyToNode(ndParent);
}
private void addDependencyToNode(XmlNode nd)
{
XmlNode depNode = _doc.CreateElement("DependentUpon",nd.NamespaceURI );
//determine name value
//get include name
string nodevalue=nd.Attributes.GetNamedItem("Include").Value;
//get first name after the directory entries
string[] pathsplit =nodevalue.Split(new string[]{"\\"},StringSplitOptions.None);
nodevalue = pathsplit[pathsplit.Length-1];
//get form name
string[] extensionsplit = nodevalue.Split(new string[] { "." }, StringSplitOptions.None);
depNode.InnerText = extensionsplit[0] + ".vb";
nd.AppendChild(depNode);
}