vspc-general Mailing List for Visual Studio Project Converter
Brought to you by:
skidder
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
---|
From: Nikolay S. <nik...@re...> - 2009-09-10 08:29:28
|
Hello, Caerwyn! I applied the change that you supplied, quickly tested, re-built the project and uploaded release to SourceForge. You may want to check out my other projects, maybe you like them too. :-) http://sourceforge.net/projects/olap-navigator/ http://sourceforge.net/projects/firebird/ http://www.red-soft.biz/en Caerwyn Pearce wrote: > > Hi, > > First off thanks for a very useful project. > > I’ve been converting projects form VS2008 to VS2005. > > The resultant projects are readable in VS2005 but can’t be double > clicked and don’t have the correct icon. > > The conversion process is converting the version number from 10.00 to > 9.000 (with three zeroes). > > The problem seems to be in SolutionConverter.cs at line 175 which I’ve > corrected as follows. > > From > > solution*.*nodeName *=* > solution*.*nodeName*.*Replace(ver*.*Substring(0, compareLen), > verTo*.*Substring(0, compareLen)); > > I don’t think the substring extraction is necessary, you need to > replace the entire version string. > > That works for me converting between VS2005 and VS2008. > > There may be other circumstances which I haven’t taken into account. > > solution*.*nodeName *=* solution*.*nodeName*.*Replace(ver, verTo); > > Best Regards > > Caerwyn > -- Nikolay Samofatov, MBA Red Soft Corporation +7 495 668 3735 |
From: Caerwyn P. <ca...@ca...> - 2009-09-09 21:02:10
|
Hi, First off thanks for a very useful project. I've been converting projects form VS2008 to VS2005. The resultant projects are readable in VS2005 but can't be double clicked and don't have the correct icon. The conversion process is converting the version number from 10.00 to 9.000 (with three zeroes). The problem seems to be in SolutionConverter.cs at line 175 which I've corrected as follows. >From solution.nodeName = solution.nodeName.Replace(ver.Substring(0, compareLen), verTo.Substring(0, compareLen)); I don't think the substring extraction is necessary, you need to replace the entire version string. That works for me converting between VS2005 and VS2008. There may be other circumstances which I haven't taken into account. solution.nodeName = solution.nodeName.Replace(ver, verTo); Best Regards Caerwyn |
From: Nikolay S. <sk...@us...> - 2009-07-21 09:20:23
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4281 Modified Files: AssemblyInfo.cs Added Files: changes.txt Log Message: Bump version --- NEW FILE: changes.txt --- Version 0.9.2 ------------- 2009-07-21 John Carlson: fixed solution parsing with when platform name contains parentheses 2009-07-21 John Carlson: fixed crash when solution version is on the second line, not the first one Version 0.9b ------------ 2009-03-03 Added support for Visual Studio C++ projects versions 2005 and 2008 Version 0.3b ------------ 2004-01-05 Added support for converting project dependencies Version 0.2b ------------ Supports conversions of VB.NET, C# and C++ projects for Visual Studio .NET 2002 and 2003 Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/vspc/vspc/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- AssemblyInfo.cs 4 Mar 2009 01:00:06 -0000 1.4 +++ AssemblyInfo.cs 21 Jul 2009 09:20:17 -0000 1.5 @@ -43,7 +43,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.1.0")] +[assembly: AssemblyVersion("0.9.2.0")] // // In order to sign your assembly you must specify a key to use. Refer to the |
From: Nikolay S. <sk...@us...> - 2009-07-21 09:07:13
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2793 Modified Files: SolutionNode.cs Log Message: Apply patch by John Carlson which fixes issues with platform names containing parentheses Index: SolutionNode.cs =================================================================== RCS file: /cvsroot/vspc/vspc/SolutionNode.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SolutionNode.cs 3 Mar 2009 20:18:46 -0000 1.2 +++ SolutionNode.cs 21 Jul 2009 09:07:04 -0000 1.3 @@ -81,6 +81,7 @@ if (line.Trim() == sectionTerminator) return null; } while (line.Trim().Length == 0 || line[0] == '#'); + // NOTE: '#' denotes a comment in the solution file int pos = 0; SolutionNode node = new SolutionNode(); @@ -88,10 +89,24 @@ char c = '\0'; // Get node name + bool ignore_parentheses = false; while (pos < line.Length) { c = line[pos]; - if (!quoted && (c == '=' || c == '(')) break; + if (!quoted) + { + // NOTE: '|' seperates actual configuration name and platform name. + // Some platform names include parentheses, for example: + // Debug|STANDARDSDK_500 (ARMV4I) = Debug|STANDARDSDK_500 (ARMV4I) + // So ignore parentheses when if we encounter a '|' before an '=' + // because we are parsing a platform name. + if (c == '|') ignore_parentheses = true; + + if (c == '=') break; + + if ((c == '(') && !ignore_parentheses) + break; + } if (c == '"') quoted = !quoted; pos++; } @@ -142,7 +157,24 @@ static public SolutionNode parseSolution(StreamReader reader) { + // I think this is to read in the first line of the solution. + // Here we are ASSUMING that the first line ALWAYS contains + // the solution format version. + // However, it seems that VS2005 uses an EMPTY line for line 1 + // and has this information on the 2nd line! + // Solution Format Version example, for VS2003: + // Microsoft Visual Studio Solution File, Format Version 8.00 string line = reader.ReadLine(); + // Check if the first line is empty. If so, we are ASSUMING + // that the Solution Format Version is on line 2 instead of 1. + // FIXME: The proper way to do this is to make sure we are + // reading in the Solution Format Version by seeing + // if the read line contains: + // "Microsoft Visual Studio Solution File" + // or possibly even more restrictive: + // "Microsoft Visual Studio Solution File, Format Version" + if (line.Length == 0) + line = reader.ReadLine(); SolutionNode rootNode = new SolutionNode(); rootNode.nodeType = NodeType.ntRoot; rootNode.nodeName = line; |
From: Nikolay S. <sk...@us...> - 2009-03-04 01:00:10
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16930 Modified Files: AssemblyInfo.cs Log Message: Bump version for 0.9.1 Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/vspc/vspc/AssemblyInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- AssemblyInfo.cs 3 Mar 2009 21:13:45 -0000 1.3 +++ AssemblyInfo.cs 4 Mar 2009 01:00:06 -0000 1.4 @@ -43,7 +43,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.0.0")] +[assembly: AssemblyVersion("0.9.1.0")] // // In order to sign your assembly you must specify a key to use. Refer to the |
From: Nikolay S. <sk...@us...> - 2009-03-04 00:53:50
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16326 Modified Files: VCProjectConverter.cs Log Message: Fix NPE error Index: VCProjectConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/VCProjectConverter.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- VCProjectConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 +++ VCProjectConverter.cs 4 Mar 2009 00:53:47 -0000 1.3 @@ -250,7 +250,8 @@ XmlNode platformNode = doc.DocumentElement.SelectSingleNode( "/VisualStudioProject/Platforms/Platform[@Name='x64']"); - platformNode.ParentNode.RemoveChild(platformNode); + if (platformNode != null) + platformNode.ParentNode.RemoveChild(platformNode); // Remove related configurations ArrayList nodesToRemove = new ArrayList(); |
From: Nikolay S. <sk...@us...> - 2009-03-03 21:13:48
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18279 Modified Files: AssemblyInfo.cs Log Message: Update version Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/vspc/vspc/AssemblyInfo.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- AssemblyInfo.cs 3 Mar 2009 20:18:46 -0000 1.2 +++ AssemblyInfo.cs 3 Mar 2009 21:13:45 -0000 1.3 @@ -23,7 +23,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. // -[assembly: AssemblyTitle("")] +[assembly: AssemblyTitle("Visual Studio Project Converter")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] @@ -43,7 +43,7 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.1.0.0")] +[assembly: AssemblyVersion("0.9.0.0")] // // In order to sign your assembly you must specify a key to use. Refer to the |
From: Nikolay S. <sk...@us...> - 2009-03-03 20:18:50
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30865 Modified Files: Application.cs AssemblyInfo.cs CSProjectConverter.cs Common.cs ConverterFactory.cs DataProjectConverter.cs SolutionConverter.cs SolutionNode.cs Utility.cs VBProjectConverter.cs VCProjectConverter.cs WszFileConverter.cs vspc.csproj Added Files: COPYING StudioVersionProfile.cs Log Message: The changes to add support for C++ projects of Visual Studio 2005 and 2008 Index: VCProjectConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/VCProjectConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- VCProjectConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ VCProjectConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,12 +1,112 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.Text; using System.Collections; using System.IO; using System.Xml; +using System.Diagnostics; public class VCProjectConverter : IFileConverter { + + private XmlElement FindCreateElement(XmlElement parent, string tagName, string name) + { + XmlElement elem = null; + if (name != "") + { + foreach (XmlNode node in parent.ChildNodes) + { + if (node.NodeType == XmlNodeType.Element) + { + XmlElement temp = (XmlElement)node; + if (temp.Name == tagName && temp.GetAttribute("Name") == name) + { + elem = temp; + break; + } + } + } + } + + if (elem == null) + { + elem = parent.OwnerDocument.CreateElement(tagName); + parent.AppendChild(elem); + } + + return elem; + } + + private void MergeNode(XmlElement target, XmlElement source) + { + // Set attributes + foreach (XmlAttribute attr in source.Attributes) + { + string attrName = attr.Name; + if (!target.HasAttribute(attrName)) + target.SetAttribute(attrName, attr.Value); + else + { + string targetAttrValue = target.GetAttribute(attrName); + + if (targetAttrValue.IndexOf("$(NoInherit)") >= 0) + continue; + + if (targetAttrValue.IndexOf("$(Inherit)") >= 0) + { + targetAttrValue.Replace("$(Inherit)", attr.Value); + } + else if (attrName == "AdditionalIncludeDirectories") + { + targetAttrValue = targetAttrValue + ';' + attr.Value; + } + else if (attrName == "AdditionalOptions" || attrName == "AdditionalDependencies") + { + targetAttrValue = targetAttrValue + ' ' + attr.Value; + } + target.SetAttribute(attrName, targetAttrValue); + } + } + + foreach (XmlNode node in source.ChildNodes) + { + // Recoursively merge child elements + if (node.NodeType == XmlNodeType.Element) + { + XmlElement temp = (XmlElement)node; + XmlElement childElement = FindCreateElement(target, temp.Name, temp.GetAttribute("Name")); + MergeNode(childElement, temp); + } + } + } + + private void MergePropertySheet(XmlElement configElement, string sheetFileName) + { + XmlDocument doc = new XmlDocument(); + doc.Load(sheetFileName); + doc.DocumentElement.RemoveAttribute("ProjectType"); + doc.DocumentElement.RemoveAttribute("Version"); + doc.DocumentElement.RemoveAttribute("Name"); + MergeNode(configElement, doc.DocumentElement); + } + public void Convert(Settings settings) { Utility.MakeWritable(settings.FileName); @@ -16,13 +116,12 @@ if ((settings.Flags & SettingsFlags.CreateBackups) != 0) Utility.Backup(settings.DumpBin, settings.FileName); - ProjectInfo piFrom = (settings.Action == Action.Downgrade) ? NewInfo : OldInfo; - ProjectInfo piTo = (settings.Action == Action.Downgrade) ? OldInfo : NewInfo; - settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2} ({3})... ", + ProjectInfo piFrom = getPi(settings.OldVersion); + ProjectInfo piTo = getPi(settings.NewVersion); + settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2}... ", shortName, piFrom.VersionName, - piTo.VersionName, - settings.Action.ToString().ToLower()); + piTo.VersionName); XmlNode prjNode = doc.DocumentElement.SelectSingleNode("//VisualStudioProject"); XmlNode prjVer = prjNode.Attributes["Version"]; @@ -40,7 +139,9 @@ // convert... prjVer.InnerText = piTo.Version; - if (settings.Action == Action.Downgrade) + // Downgrade to VS2002 + if (settings.NewVersion <= SolutionVersion.VS2002 && + settings.OldVersion >= SolutionVersion.VS2003) { // if we are making a downgrade, we should get the <References> node // and append the .dlls (#using) in stdafx.h (if the user wanted this) @@ -59,7 +160,10 @@ } } } - else // upgrade + + // Upgrade to VS2003 or later + if (settings.OldVersion <= SolutionVersion.VS2002 && + settings.NewVersion >= SolutionVersion.VS2003) { // if we are making an upgrade, we should create the <References> node // and append the .dlls from stdafx.h (if the user wanted this) @@ -76,13 +180,18 @@ foreach (XmlNode lnkNode in linkerNodes) { XmlAttribute depAtt = lnkNode.Attributes["AdditionalDependencies"]; - if (settings.Action == Action.Downgrade) + // Downgrade to VS2002 + if (settings.NewVersion <= SolutionVersion.VS2002 && + settings.OldVersion >= SolutionVersion.VS2003) { // remove the nochkclr.obj from AdditionalDependencies if (depAtt != null) depAtt.InnerText = depAtt.InnerText.Replace("nochkclr.obj", ""); } - else // upgrade + + // Upgrade from VS2002 + if (settings.OldVersion <= SolutionVersion.VS2002 && + settings.NewVersion >= SolutionVersion.VS2003) { // append (if not exist) nochkclr.obj to AdditionalDependencies if (depAtt != null) @@ -114,7 +223,7 @@ } // sorry guys, VC 2002 does not support resX files:(; no designer, remember?:) - if (settings.Action == Action.Downgrade) + if (settings.NewVersion <= SolutionVersion.VS2002) { ArrayList nodesToRemove = new ArrayList(); // find .resX files and convert them @@ -132,6 +241,67 @@ foreach (XmlNode nodeToRemove in nodesToRemove) nodeToRemove.ParentNode.RemoveChild(nodeToRemove); } + + // Versions prior to Visual Studio 2005 do not support x64. + // Clean up all mentions of this platform otherwise project will not load + if (settings.NewVersion < SolutionVersion.VS2005) + { + // Remove platform itself + XmlNode platformNode = + doc.DocumentElement.SelectSingleNode( + "/VisualStudioProject/Platforms/Platform[@Name='x64']"); + platformNode.ParentNode.RemoveChild(platformNode); + + // Remove related configurations + ArrayList nodesToRemove = new ArrayList(); + XmlNodeList resRefs = doc.DocumentElement.SelectNodes( + "//Configuration[contains(@Name, '|x64')] | //FileConfiguration[contains(@Name, '|x64')]"); + foreach (XmlNode resRef in resRefs) + { + XmlAttribute refAtt = resRef.Attributes["Name"]; + if (!refAtt.InnerText.EndsWith("|x64")) + continue; + nodesToRemove.Add(resRef); + } + // remove the nodes + foreach (XmlNode nodeToRemove in nodesToRemove) + nodeToRemove.ParentNode.RemoveChild(nodeToRemove); + } + + // Versions prior to Visual Studio 2005 do not support property sheets. + // Merge them into project files. + if (settings.NewVersion < SolutionVersion.VS2005) + { + XmlNodeList resRefs = doc.DocumentElement.SelectNodes("//Configuration"); + foreach (XmlNode resRef in resRefs) + { + XmlAttribute refAtt = resRef.Attributes["InheritedPropertySheets"]; + if (refAtt != null) + { + string[] sheets = refAtt.Value.Split(new char[]{';'}); + foreach (string sheet in sheets) + { + string sheetFileName = Utility.GetRealFileName( + Path.GetDirectoryName(settings.FileName), + sheet); + try + { + settings.DumpBin.WriteLine("Merging property sheet \"{0}\"", sheetFileName); + MergePropertySheet((XmlElement)resRef, sheetFileName); + } + catch(FileNotFoundException) + { + settings.DumpBin.WriteLine("File not found"); + } + catch(DirectoryNotFoundException) + { + settings.DumpBin.WriteLine("File not found"); + } + } + } + resRef.Attributes.Remove(refAtt); + } + } // find .VSZ files and convert them XmlNodeList vszRefs = doc.DocumentElement.SelectNodes("//File[contains(@RelativePath, '.vsz')]"); @@ -150,7 +320,8 @@ string extension = Path.GetExtension(wizardFile); IFileConverter converter = ConverterFactory.Create(extension); Settings fileSettings = new Settings( - settings.Action, + settings.OldVersion, + settings.NewVersion, wizardFile, settings.Flags, settings.DumpBin); @@ -244,18 +415,40 @@ private class ProjectInfo { public ProjectInfo( - string versionName, + SolutionVersion solVersion, string version) { - VersionName = versionName; + SolVersion = solVersion; Version = version; } - public readonly string VersionName; + public readonly SolutionVersion SolVersion; public readonly string Version; + + public string VersionName + { + get + { + return (StudioVersionProfile.getVsProfile(SolVersion).VersionName); + } + } + } // ProjectInfo #endregion class ProjectInfo - - private static readonly ProjectInfo OldInfo = new ProjectInfo("VS.NET 2002", "7.00"); - private static readonly ProjectInfo NewInfo = new ProjectInfo("VS.NET 2003", "7.10"); + + private static readonly ProjectInfo[] ProjectsInfo = + { + null, + new ProjectInfo(SolutionVersion.VS2002, "7.00"), + new ProjectInfo(SolutionVersion.VS2003, "7.10"), + new ProjectInfo(SolutionVersion.VS2005, "8.00"), + new ProjectInfo(SolutionVersion.VS2008, "9,00") + }; + + private static ProjectInfo getPi(SolutionVersion solVersion) + { + ProjectInfo pi = ProjectsInfo[(int)solVersion]; + Debug.Assert(pi.SolVersion == solVersion); + return pi; + } } // VCProjectConverter Index: ConverterFactory.cs =================================================================== RCS file: /cvsroot/vspc/vspc/ConverterFactory.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- ConverterFactory.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ ConverterFactory.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; --- NEW FILE: COPYING --- GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) 19yy <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. Index: Common.cs =================================================================== RCS file: /cvsroot/vspc/vspc/Common.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Common.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ Common.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.Diagnostics; @@ -18,12 +35,14 @@ // enums -public enum Action +public enum SolutionVersion { - Invalid = -1, - Downgrade = 0, - Upgrade = 1 -} // Action + Invalid = 0, + VS2002 = 1, + VS2003 = 2, + VS2005 = 3, + VS2008 = 4 +} // SolutionVersion [Flags] public enum SettingsFlags : int @@ -43,26 +62,40 @@ public sealed class Settings { public Settings( - Action action, + SolutionVersion oldVersion, + SolutionVersion newVersion, string fileName, SettingsFlags flags, IDumpBin dumpBin) { - this.action = action; + this.oldVersion = oldVersion; + this.newVersion = newVersion; this.fileName = fileName; this.flags = flags; this.dumpBin = dumpBin; } - public Action Action + public SolutionVersion OldVersion { get { - return (action); + return (oldVersion); } set { - action = value; + oldVersion = value; + } + } + + public SolutionVersion NewVersion + { + get + { + return (newVersion); + } + set + { + newVersion = value; } } @@ -104,7 +137,7 @@ } } - private Action action; + private SolutionVersion oldVersion, newVersion; private string fileName; private SettingsFlags flags; private IDumpBin dumpBin; Index: SolutionNode.cs =================================================================== RCS file: /cvsroot/vspc/vspc/SolutionNode.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SolutionNode.cs 3 Mar 2009 19:50:47 -0000 1.1 +++ SolutionNode.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.Collections; using System.IO; @@ -63,7 +80,7 @@ } if (line.Trim() == sectionTerminator) return null; - } while (line.Trim().Length == 0); + } while (line.Trim().Length == 0 || line[0] == '#'); int pos = 0; SolutionNode node = new SolutionNode(); @@ -161,9 +178,13 @@ } } - static public void streamSolution(StreamWriter writer, SolutionNode rootNode) + static public void streamSolution(StreamWriter writer, + SolutionNode rootNode, SolutionVersion formatVersion) { writer.WriteLine(rootNode.nodeName); // Version, etc + string formatString = StudioVersionProfile.getVsProfile(formatVersion).SolutionFormatString; + if (formatString != null) + writer.WriteLine(formatString); foreach (SolutionNode node in rootNode.sectionItems) node.streamNode(writer, 0); } Index: Utility.cs =================================================================== RCS file: /cvsroot/vspc/vspc/Utility.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Utility.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ Utility.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.IO; using System.DirectoryServices; Index: DataProjectConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/DataProjectConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- DataProjectConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ DataProjectConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/vspc/vspc/AssemblyInfo.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- AssemblyInfo.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ AssemblyInfo.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System.Reflection; using System.Runtime.CompilerServices; Index: vspc.csproj =================================================================== RCS file: /cvsroot/vspc/vspc/vspc.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- vspc.csproj 3 Mar 2009 19:50:47 -0000 1.2 +++ vspc.csproj 3 Mar 2009 20:18:46 -0000 1.3 @@ -129,6 +129,11 @@ BuildAction = "Compile" /> <File + RelPath = "StudioVersionProfile.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Utility.cs" SubType = "Code" BuildAction = "Compile" Index: VBProjectConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/VBProjectConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- VBProjectConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ VBProjectConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.IO; using System.Xml; @@ -13,14 +30,23 @@ doc.Load(settings.FileName); if ((settings.Flags & SettingsFlags.CreateBackups) != 0) Utility.Backup(settings.DumpBin, settings.FileName); + + if (settings.OldVersion > SolutionVersion.VS2003 || + settings.OldVersion > SolutionVersion.VS2003) + { + // NS: Somebody will need to fix this + string message = String.Format( + "The project \"{0}\" cannot be converted. Only Visual Studio versions 2002 and 2003 are supported for .NET projects.", + shortName); + throw (new ApplicationException(message)); + } - ProjectInfo piFrom = (settings.Action == Action.Downgrade) ? NewInfo : OldInfo; - ProjectInfo piTo = (settings.Action == Action.Downgrade) ? OldInfo : NewInfo; - settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2} ({3})... ", + ProjectInfo piFrom = (settings.OldVersion == SolutionVersion.VS2003) ? NewInfo : OldInfo; + ProjectInfo piTo = (settings.NewVersion == SolutionVersion.VS2002) ? OldInfo : NewInfo; + settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2}... ", shortName, piFrom.VersionName, - piTo.VersionName, - settings.Action.ToString().ToLower()); + piTo.VersionName); XmlNode prjNode = doc.DocumentElement.SelectSingleNode("//VisualStudioProject/VisualBasic"); XmlNode prjVer = prjNode.Attributes["ProductVersion"]; Index: SolutionConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/SolutionConverter.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SolutionConverter.cs 3 Mar 2009 19:50:47 -0000 1.2 +++ SolutionConverter.cs 3 Mar 2009 20:18:46 -0000 1.3 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.Diagnostics; using System.IO; @@ -5,6 +22,120 @@ public sealed class SolutionConverter : IFileConverter { + public void makeGlobalDependencies(SolutionNode solution) + { + SolutionNode globalSection = + SolutionNode.findCreateSectionBefore(solution, "Global", null, true, null, null); + + SolutionNode glDepSection = SolutionNode.findCreateSectionBefore( + globalSection, "GlobalSection", "ProjectDependencies", true, "GlobalSection", "ProjectConfiguration"); + glDepSection.nodeValue = "postSolution"; + // Move dependencies from individual projects section to global section + foreach(SolutionNode project in solution.sectionItems) + { + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) + { + continue; + } + SolutionNode prjDeps = null; + int prjDepSectionIndex; + for (prjDepSectionIndex=0; prjDepSectionIndex < project.sectionItems.Count; prjDepSectionIndex++) + { + SolutionNode node = (SolutionNode)project.sectionItems[prjDepSectionIndex]; + if (node.nodeType == SolutionNode.NodeType.ntSection && + node.nodeName == "ProjectSection" && + node.sectionName == "ProjectDependencies") + { + prjDeps = node; + break; + } + } + + if (prjDeps == null) continue; + string prjGuid = project.getValue(3); + if (prjGuid == null) continue; // .sln file is invalid or unrecognized, probably + int n = 0; + for(int i=0; i<prjDeps.sectionItems.Count;i++) + { + SolutionNode prjDep = (SolutionNode)prjDeps.sectionItems[i]; + if (prjDep.nodeType != SolutionNode.NodeType.ntItem) + { + continue; + } + SolutionNode.findCreateValue(glDepSection, prjGuid + "." + n, prjDep.nodeValue); + n++; + } + project.sectionItems.RemoveAt(prjDepSectionIndex); + } + } + + public void makeLocalDependencies(SolutionNode solution) + { + SolutionNode globalSection = + SolutionNode.findCreateSectionBefore(solution, "Global", null, true, null, null); + + // Create dependency node for all projects + foreach(SolutionNode project in solution.sectionItems) + { + // Skip non-project nodes + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) + { + continue; + } + SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(project, "ProjectSection", "ProjectDependencies", + true, null, null); + prjDeps.nodeValue = "postProject"; + } + + // Move from global section to projects section + SolutionNode glDepSection = null; + int glDepSectionIndex; + for (glDepSectionIndex=0; glDepSectionIndex < globalSection.sectionItems.Count; glDepSectionIndex++) + { + SolutionNode node = (SolutionNode)globalSection.sectionItems[glDepSectionIndex]; + if (node.nodeType == SolutionNode.NodeType.ntSection && + node.nodeName == "GlobalSection" && + node.sectionName == "ProjectDependencies") + { + glDepSection = node; + break; + } + } + if (glDepSection != null) + { + foreach(SolutionNode depNode in glDepSection.sectionItems) + { + string[] depParts = depNode.nodeName.Split(new char[]{'.'}); + + SolutionNode prjNode = null; + foreach(SolutionNode project in solution.sectionItems) + { + // Skip non-project nodes + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) + { + continue; + } + if (project.getValue(3) == depParts[0]) + { + prjNode = project; + break; + } + } + + if (prjNode == null) continue; // Problem with solution file + + // Assumed to be found! + SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(prjNode, "ProjectSection", "ProjectDependencies", + false, null, null); + SolutionNode.findCreateValue(prjDeps, depNode.nodeValue, depNode.nodeValue); + } + globalSection.sectionItems.RemoveAt(glDepSectionIndex); + } + } + public void Convert(Settings settings) { Utility.MakeWritable(settings.FileName); @@ -12,13 +143,14 @@ if ((settings.Flags & SettingsFlags.CreateBackups) != 0) Utility.Backup(settings.DumpBin, settings.FileName); - string verFrom = (settings.Action == Action.Downgrade) ? newVersion : oldVersion; - string verTo = (settings.Action == Action.Downgrade) ? oldVersion : newVersion; - settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2} ({3})... ", + string verFrom = + StudioVersionProfile.getVsProfile(settings.OldVersion).SolutionVersionString; + string verTo = + StudioVersionProfile.getVsProfile(settings.NewVersion).SolutionVersionString; + settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2}... ", shortName, verFrom, - verTo, - settings.Action.ToString().ToLower()); + verTo); StreamReader reader = new StreamReader(settings.FileName); StreamWriter writer = new StreamWriter(settings.FileName + ".cvttmp", false); @@ -41,120 +173,22 @@ } solution.nodeName = solution.nodeName.Replace(ver.Substring(0, compareLen), verTo.Substring(0, compareLen)); - // Update projects dependencies - - // find/create "Global" section - SolutionNode globalSection = - SolutionNode.findCreateSectionBefore(solution, "Global", null, true, null, null); - - if (settings.Action == Action.Downgrade) + // Downgrade to VS2002 - move dependencies + if (settings.NewVersion <= SolutionVersion.VS2002 && + settings.OldVersion >= SolutionVersion.VS2003) { - SolutionNode glDepSection = SolutionNode.findCreateSectionBefore( - globalSection, "GlobalSection", "ProjectDependencies", true, "GlobalSection", "ProjectConfiguration"); - glDepSection.nodeValue = "postSolution"; - // Move dependencies from individual projects section to global section - foreach(SolutionNode project in solution.sectionItems) - { - if (project.nodeType != SolutionNode.NodeType.ntSection || - project.nodeName != "Project" || project.nodeValue == null) - { - continue; - } - SolutionNode prjDeps = null; - int prjDepSectionIndex; - for (prjDepSectionIndex=0; prjDepSectionIndex < project.sectionItems.Count; prjDepSectionIndex++) - { - SolutionNode node = (SolutionNode)project.sectionItems[prjDepSectionIndex]; - if (node.nodeType == SolutionNode.NodeType.ntSection && - node.nodeName == "ProjectSection" && - node.sectionName == "ProjectDependencies") - { - prjDeps = node; - break; - } - } - - if (prjDeps == null) continue; - string prjGuid = project.getValue(3); - if (prjGuid == null) continue; // .sln file is invalid or unrecognized, probably - int n = 0; - for(int i=0; i<prjDeps.sectionItems.Count;i++) - { - SolutionNode prjDep = (SolutionNode)prjDeps.sectionItems[i]; - if (prjDep.nodeType != SolutionNode.NodeType.ntItem) - { - continue; - } - SolutionNode.findCreateValue(glDepSection, prjGuid + "." + n, prjDep.nodeValue); - n++; - } - project.sectionItems.RemoveAt(prjDepSectionIndex); - } + makeGlobalDependencies(solution); } - else - { - // Create dependency node for all projects - foreach(SolutionNode project in solution.sectionItems) - { - // Skip non-project nodes - if (project.nodeType != SolutionNode.NodeType.ntSection || - project.nodeName != "Project" || project.nodeValue == null) - { - continue; - } - SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(project, "ProjectSection", "ProjectDependencies", - true, null, null); - prjDeps.nodeValue = "postProject"; - } - - // Move from global section to projects section - SolutionNode glDepSection = null; - int glDepSectionIndex; - for (glDepSectionIndex=0; glDepSectionIndex < globalSection.sectionItems.Count; glDepSectionIndex++) { - SolutionNode node = (SolutionNode)globalSection.sectionItems[glDepSectionIndex]; - if (node.nodeType == SolutionNode.NodeType.ntSection && - node.nodeName == "GlobalSection" && - node.sectionName == "ProjectDependencies") - { - glDepSection = node; - break; - } - } - if (glDepSection != null) - { - foreach(SolutionNode depNode in glDepSection.sectionItems) - { - string[] depParts = depNode.nodeName.Split(new char[]{'.'}); - - SolutionNode prjNode = null; - foreach(SolutionNode project in solution.sectionItems) - { - // Skip non-project nodes - if (project.nodeType != SolutionNode.NodeType.ntSection || - project.nodeName != "Project" || project.nodeValue == null) - { - continue; - } - if (project.getValue(3) == depParts[0]) - { - prjNode = project; - break; - } - } - - if (prjNode == null) continue; // Problem with solution file - // Assumed to be found! - SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(prjNode, "ProjectSection", "ProjectDependencies", - false, null, null); - SolutionNode.findCreateValue(prjDeps, depNode.nodeValue, depNode.nodeValue); - } - globalSection.sectionItems.RemoveAt(glDepSectionIndex); - } + // Upgrade from VS2002 - move dependencies + if (settings.OldVersion <= SolutionVersion.VS2002 && + settings.NewVersion >= SolutionVersion.VS2003) + { + makeLocalDependencies(solution); } // Stream out converted solution file - SolutionNode.streamSolution(writer, solution); + SolutionNode.streamSolution(writer, solution, settings.NewVersion); writer.Flush(); // For debugging ease // Iterate over projects and convert them @@ -214,7 +248,8 @@ string extension = Path.GetExtension(projectFileName); IFileConverter converter = ConverterFactory.Create(extension); Settings prjSettings = new Settings( - settings.Action, + settings.OldVersion, + settings.NewVersion, projectFileName, settings.Flags, settings.DumpBin); @@ -251,8 +286,4 @@ File.Move(settings.FileName + ".cvttmp", settings.FileName); } - // 1st HACK here; C# produces 7.0 and 7.00 versions; DUH! - private const string oldVersion = "7.0"; - private const string newVersion = "8.0"; - } // SolutionConverter Index: CSProjectConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/CSProjectConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- CSProjectConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ CSProjectConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.IO; using System.Xml; @@ -14,13 +31,22 @@ if ((settings.Flags & SettingsFlags.CreateBackups) != 0) Utility.Backup(settings.DumpBin, settings.FileName); - ProjectInfo piFrom = (settings.Action == Action.Downgrade) ? NewInfo : OldInfo; - ProjectInfo piTo = (settings.Action == Action.Downgrade) ? OldInfo : NewInfo; - settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2} ({3})... ", + if (settings.OldVersion > SolutionVersion.VS2003 || + settings.OldVersion > SolutionVersion.VS2003) + { + // NS: Somebody will need to fix this + string message = String.Format( + "The project \"{0}\" cannot be converted. Only Visual Studio versions 2002 and 2003 are supported for .NET projects.", + shortName); + throw (new ApplicationException(message)); + } + + ProjectInfo piFrom = (settings.OldVersion == SolutionVersion.VS2003) ? NewInfo : OldInfo; + ProjectInfo piTo = (settings.NewVersion == SolutionVersion.VS2002) ? OldInfo : NewInfo; + settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2}... ", shortName, piFrom.VersionName, - piTo.VersionName, - settings.Action.ToString().ToLower()); + piTo.VersionName); XmlNode prjNode = doc.DocumentElement.SelectSingleNode("//VisualStudioProject/CSHARP"); XmlNode prjVer = prjNode.Attributes["ProductVersion"]; Index: WszFileConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/WszFileConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- WszFileConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ WszFileConverter.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,3 +1,20 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.IO; @@ -11,13 +28,22 @@ if ((settings.Flags & SettingsFlags.CreateBackups) != 0) Utility.Backup(settings.DumpBin, settings.FileName); - WszVersionInfo viFrom = (settings.Action == Action.Downgrade) ? NewInfo : OldInfo; - WszVersionInfo viTo = (settings.Action == Action.Downgrade) ? OldInfo : NewInfo; - settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2} ({3})... ", + if (settings.OldVersion > SolutionVersion.VS2003 || + settings.OldVersion > SolutionVersion.VS2003) + { + // NS: Somebody will need to fix this + string message = String.Format( + "The file \"{0}\" cannot be converted. Only Visual Studio versions 2002 and 2003 are supported for .NET projects.", + shortName); + throw (new ApplicationException(message)); + } + + WszVersionInfo viFrom = (settings.OldVersion == SolutionVersion.VS2003) ? NewInfo : OldInfo; + WszVersionInfo viTo = (settings.NewVersion == SolutionVersion.VS2002) ? OldInfo : NewInfo; + settings.DumpBin.WriteLine("Converting \"{0}\" from version {1} to {2}... ", shortName, viFrom.VersionName, - viTo.VersionName, - settings.Action.ToString().ToLower()); + viTo.VersionName); StreamReader reader = new StreamReader(settings.FileName); StreamWriter writer = new StreamWriter(settings.FileName + ".cvttmp", false); Index: Application.cs =================================================================== RCS file: /cvsroot/vspc/vspc/Application.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Application.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ Application.cs 3 Mar 2009 20:18:46 -0000 1.2 @@ -1,9 +1,39 @@ +/* + * This file is a part of Visual Studio Project Converter + * Copyright (C) 2004 Stoyan Damov + * Copyright (C) 2009 Nikolay Samofatov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + using System; using System.IO; public class Application { + static SolutionVersion parseVersion(string arg) + { + SolutionVersion version = SolutionVersion.Invalid; + try + { + version = (SolutionVersion)Enum.Parse(typeof(SolutionVersion), arg, true); + } + catch + { + } + return version; + } + static int Main(string[] args) { // get the options first @@ -49,27 +79,24 @@ else dumpBin = new ConsoleDumpBin(); - dumpBin.WriteLine("\nVisual Studio .NET solutions converter v.0.2b"); - dumpBin.WriteLine("Totally Free(tf:-) by Stoyan Damov"); + dumpBin.WriteLine("\nVisual Studio .NET solutions converter v.0.9b"); + dumpBin.WriteLine("Totally Free(tf:-) by Stoyan Damov. Modified by Nikolay Samofatov"); - // at least an action & a filename is expected - if (args.Length < 2) + // at least two versions & a filename is expected + if (args.Length < 3) return (Usage(dumpBin, "")); - // get action - Action action = Action.Invalid; - try - { - action = (Action)Enum.Parse(typeof(Action), args[0], true); - } - catch - { - } - if (action == Action.Invalid) - return (Usage(dumpBin, "Invalid command \"{0}\"", args[0])); + // get source and target solution versions + SolutionVersion oldVersion = parseVersion(args[0]); + if (oldVersion == SolutionVersion.Invalid) + return (Usage(dumpBin, "Invalid solution version \"{0}\"", args[0])); + + SolutionVersion newVersion = parseVersion(args[1]); + if (newVersion == SolutionVersion.Invalid) + return (Usage(dumpBin, "Invalid solution version \"{0}\"", args[1])); // get file name - string fileName = Path.GetFullPath(args[1]); + string fileName = Path.GetFullPath(args[2]); if (!File.Exists(fileName)) return (Usage(dumpBin, "The specified file \"{0}\" does not exist!", fileName)); @@ -81,7 +108,8 @@ // convert Settings settings = new Settings( - action, + oldVersion, + newVersion, fileName, flags, dumpBin); @@ -110,11 +138,13 @@ params object[] args) { string usage = @" -Usage: vspc [<command> <fileName> [/option | --longOption]] +Usage: vspc [<from version> <to version> <fileName> [/option | --longOption]] -<command>: - upgrade Upgrade from 2002 to 2003 format - downgrade Downgrade from 2003 to 2002 format +<from version> and <to version>: + One of the following - VS2002, VS2003, VS2005 or VS2008. + Note that conversion of .NET projects for version 2005 and 2008 is + currently not supported. Native C++ projects should convert just + fine between any of the above versions. <fileName>: The full solution/project file path (all projects in the solution are converted automatically, and I don't think --- NEW FILE: StudioVersionProfile.cs --- /* * This file is a part of Visual Studio Project Converter * Copyright (C) 2004 Stoyan Damov * Copyright (C) 2009 Nikolay Samofatov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ using System; using System.Diagnostics; /// <summary> /// Provides basic conversion information for a given visual studio version /// </summary> publi... [truncated message content] |
From: Nikolay S. <sk...@us...> - 2009-03-03 19:50:51
|
Update of /cvsroot/vspc/vspc In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15008 Modified Files: SolutionConverter.cs vspc.csproj vspc.sln Added Files: SolutionNode.cs Log Message: My fixes from 2004. This adds conversion of project dependencies between 2002 and 2003 Index: vspc.sln =================================================================== RCS file: /cvsroot/vspc/vspc/vspc.sln,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- vspc.sln 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ vspc.sln 3 Mar 2009 19:50:47 -0000 1.2 @@ -1,10 +1,12 @@ -Microsoft Visual Studio Solution File, Format Version 7.00 +Microsoft Visual Studio Solution File, Format Version 8.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vspc", "vspc.csproj", "{00FC0E3C-2C87-481F-9A4C-800AF8AB6A3A}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection EndProject Global GlobalSection(SolutionConfiguration) = preSolution - ConfigName.0 = Debug - ConfigName.1 = Release + Debug = Debug + Release = Release EndGlobalSection GlobalSection(ProjectDependencies) = postSolution EndGlobalSection Index: vspc.csproj =================================================================== RCS file: /cvsroot/vspc/vspc/vspc.csproj,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- vspc.csproj 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ vspc.csproj 3 Mar 2009 19:50:47 -0000 1.2 @@ -1,8 +1,8 @@ <VisualStudioProject> <CSHARP ProjectType = "Local" - ProductVersion = "7.0.9466" - SchemaVersion = "1.0" + ProductVersion = "7.10.6030" + SchemaVersion = "2.0" ProjectGuid = "{00FC0E3C-2C87-481F-9A4C-800AF8AB6A3A}" > <Build> @@ -16,8 +16,11 @@ DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Exe" + PreBuildEvent = "" + PostBuildEvent = "" RootNamespace = "vspc" - StartupObject = "" + RunPostBuildEvent = "OnBuildSuccess" + StartupObject = "Application" > <Config Name = "Debug" @@ -30,6 +33,8 @@ DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" + NoStdLib = "false" + NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" @@ -48,6 +53,8 @@ DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" + NoStdLib = "false" + NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" @@ -117,6 +124,11 @@ BuildAction = "Compile" /> <File + RelPath = "SolutionNode.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Utility.cs" SubType = "Code" BuildAction = "Compile" Index: SolutionConverter.cs =================================================================== RCS file: /cvsroot/vspc/vspc/SolutionConverter.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- SolutionConverter.cs 3 Mar 2009 19:46:20 -0000 1.1.1.1 +++ SolutionConverter.cs 3 Mar 2009 19:50:47 -0000 1.2 @@ -22,13 +22,13 @@ StreamReader reader = new StreamReader(settings.FileName); StreamWriter writer = new StreamWriter(settings.FileName + ".cvttmp", false); - string line = null; try { + SolutionNode solution = SolutionNode.parseSolution(reader); + // change version... - line = reader.ReadLine(); - string[] parts = line.Split(' '); + string[] parts = solution.nodeName.Split(' '); string ver = parts[parts.Length - 1]; int compareLen = Math.Min(ver.Length, verTo.Length); if (ver.Substring(0, compareLen) == verTo.Substring(0, compareLen)) @@ -38,84 +38,205 @@ shortName, verTo); throw (new ApplicationException(message)); - } - line = line.Replace(ver.Substring(0, compareLen), verTo.Substring(0, compareLen)); - writer.WriteLine(line); - while ((line = reader.ReadLine()) != null) + } + solution.nodeName = solution.nodeName.Replace(ver.Substring(0, compareLen), verTo.Substring(0, compareLen)); + + // Update projects dependencies + + // find/create "Global" section + SolutionNode globalSection = + SolutionNode.findCreateSectionBefore(solution, "Global", null, true, null, null); + + if (settings.Action == Action.Downgrade) { - writer.WriteLine(line); - // regex is overkill here, as I know the exact format, which is: - // - // Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vspc", "vspc.csproj", "{00FC0E3C-2C87-481F-9A4C-800AF8AB6A3A}" - if (line.StartsWith("Project(")) + SolutionNode glDepSection = SolutionNode.findCreateSectionBefore( + globalSection, "GlobalSection", "ProjectDependencies", true, "GlobalSection", "ProjectConfiguration"); + glDepSection.nodeValue = "postSolution"; + // Move dependencies from individual projects section to global section + foreach(SolutionNode project in solution.sectionItems) { - // get the project file name - int pos = line.IndexOf("="); - pos = line.IndexOf(",", pos); // skip project name - pos = line.IndexOf("\"", pos); - // we are at the starting quote, so skip it - pos++; - int closeQuote = line.IndexOf("\"", pos); - string projectFileName = line.Substring(pos, closeQuote - pos); - // check whether the project is a web one - bool isWebProject = projectFileName.ToLower().StartsWith("http://"); - if (isWebProject && (settings.Flags & SettingsFlags.WebProjects) == 0) + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) { - settings.DumpBin.WriteLine( - "Skipping web project {0}. Run the tool separately on the project file.", - projectFileName); continue; } - // get project path - if (isWebProject) + SolutionNode prjDeps = null; + int prjDepSectionIndex; + for (prjDepSectionIndex=0; prjDepSectionIndex < project.sectionItems.Count; prjDepSectionIndex++) { - settings.DumpBin.WriteLine("Resolving \"{0}\" location...", projectFileName); - projectFileName = Utility.GetWebFileName(projectFileName); - if (projectFileName == null) + SolutionNode node = (SolutionNode)project.sectionItems[prjDepSectionIndex]; + if (node.nodeType == SolutionNode.NodeType.ntSection && + node.nodeName == "ProjectSection" && + node.sectionName == "ProjectDependencies") + { + prjDeps = node; + break; + } + } + + if (prjDeps == null) continue; + string prjGuid = project.getValue(3); + if (prjGuid == null) continue; // .sln file is invalid or unrecognized, probably + int n = 0; + for(int i=0; i<prjDeps.sectionItems.Count;i++) + { + SolutionNode prjDep = (SolutionNode)prjDeps.sectionItems[i]; + if (prjDep.nodeType != SolutionNode.NodeType.ntItem) { - settings.DumpBin.WriteLine("Could not resolve web project file's location, skipping..."); continue; } + SolutionNode.findCreateValue(glDepSection, prjGuid + "." + n, prjDep.nodeValue); + n++; } - else + project.sectionItems.RemoveAt(prjDepSectionIndex); + } + } + else + { + // Create dependency node for all projects + foreach(SolutionNode project in solution.sectionItems) + { + // Skip non-project nodes + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) { - // VC++ writes relative paths, so a little more work is necessary - projectFileName = Utility.GetRealFileName( - Path.GetDirectoryName(settings.FileName), - projectFileName); + continue; } + SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(project, "ProjectSection", "ProjectDependencies", + true, null, null); + prjDeps.nodeValue = "postProject"; + } - // convert projects one by one, in an exception block, so if one - // fails, the rest get converted... - try - { - string extension = Path.GetExtension(projectFileName); - IFileConverter converter = ConverterFactory.Create(extension); - Settings prjSettings = new Settings( - settings.Action, - projectFileName, - settings.Flags, - settings.DumpBin); - if (converter != null) - { - converter.Convert(prjSettings); - } - else + // Move from global section to projects section + SolutionNode glDepSection = null; + int glDepSectionIndex; + for (glDepSectionIndex=0; glDepSectionIndex < globalSection.sectionItems.Count; glDepSectionIndex++) { + SolutionNode node = (SolutionNode)globalSection.sectionItems[glDepSectionIndex]; + if (node.nodeType == SolutionNode.NodeType.ntSection && + node.nodeName == "GlobalSection" && + node.sectionName == "ProjectDependencies") + { + glDepSection = node; + break; + } + } + if (glDepSection != null) + { + foreach(SolutionNode depNode in glDepSection.sectionItems) + { + string[] depParts = depNode.nodeName.Split(new char[]{'.'}); + + SolutionNode prjNode = null; + foreach(SolutionNode project in solution.sectionItems) { - settings.DumpBin.WriteLine( - "Skipping project of unknown type {0}", - Path.GetFileName(projectFileName)); + // Skip non-project nodes + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) + { + continue; + } + if (project.getValue(3) == depParts[0]) + { + prjNode = project; + break; + } } + + if (prjNode == null) continue; // Problem with solution file + + // Assumed to be found! + SolutionNode prjDeps = SolutionNode.findCreateSectionBefore(prjNode, "ProjectSection", "ProjectDependencies", + false, null, null); + SolutionNode.findCreateValue(prjDeps, depNode.nodeValue, depNode.nodeValue); } - catch (ApplicationException e) + globalSection.sectionItems.RemoveAt(glDepSectionIndex); + } + } + + // Stream out converted solution file + SolutionNode.streamSolution(writer, solution); + writer.Flush(); // For debugging ease + + // Iterate over projects and convert them + foreach(SolutionNode project in solution.sectionItems) + { + // Skip non-project nodes + if (project.nodeType != SolutionNode.NodeType.ntSection || + project.nodeName != "Project" || project.nodeValue == null) + { + continue; + } + + // regex is overkill here, as I know the exact format, which is: + // + // Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vspc", "vspc.csproj", "{00FC0E3C-2C87-481F-9A4C-800AF8AB6A3A}" + + // get the project file name + string val = project.nodeValue; + int pos = val.IndexOf(","); // skip project name + pos = val.IndexOf("\"", pos); + // we are at the starting quote, so skip it + pos++; + int closeQuote = val.IndexOf("\"", pos); + string projectFileName = val.Substring(pos, closeQuote - pos); + // check whether the project is a web one + bool isWebProject = projectFileName.ToLower().StartsWith("http://"); + if (isWebProject && (settings.Flags & SettingsFlags.WebProjects) == 0) + { + settings.DumpBin.WriteLine( + "Skipping web project {0}. Run the tool separately on the project file.", + projectFileName); + continue; + } + // get project path + if (isWebProject) + { + settings.DumpBin.WriteLine("Resolving \"{0}\" location...", projectFileName); + projectFileName = Utility.GetWebFileName(projectFileName); + if (projectFileName == null) { - settings.DumpBin.WriteLine("\n\nError: {0}\n", e.Message); + settings.DumpBin.WriteLine("Could not resolve web project file's location, skipping..."); + continue; } - catch (Exception e) + } + else + { + // VC++ writes relative paths, so a little more work is necessary + projectFileName = Utility.GetRealFileName( + Path.GetDirectoryName(settings.FileName), + projectFileName); + } + + // convert projects one by one, in an exception block, so if one + // fails, the rest get converted... + try + { + string extension = Path.GetExtension(projectFileName); + IFileConverter converter = ConverterFactory.Create(extension); + Settings prjSettings = new Settings( + settings.Action, + projectFileName, + settings.Flags, + settings.DumpBin); + if (converter != null) { - settings.DumpBin.WriteLine("\n\nUnexpected error occurred. Technical information follows:\n{0}\n", e); + converter.Convert(prjSettings); } - } // if (is a project line) + else + { + settings.DumpBin.WriteLine( + "Skipping project of unknown type {0}", + Path.GetFileName(projectFileName)); + } + } + catch (ApplicationException e) + { + settings.DumpBin.WriteLine("\n\nError: {0}\n", e.Message); + } + catch (Exception e) + { + settings.DumpBin.WriteLine("\n\nUnexpected error occurred. Technical information follows:\n{0}\n", e); + } } // while (can read...) } finally --- NEW FILE: SolutionNode.cs --- using System; using System.Collections; using System.IO; using System.Text; /// <summary> /// Summary description for SolutionNode. /// </summary> public sealed class SolutionNode { public enum NodeType {ntRoot, ntItem, ntSection}; public NodeType nodeType; public string nodeName; public string nodeValue; public string sectionName; public ArrayList sectionItems; public SolutionNode() { } public string getValue(int n) { int cur_n = 1; int pos = 0; bool quoted = false; StringBuilder s = new StringBuilder(); while (pos < nodeValue.Length) { char c = nodeValue[pos]; if (!quoted && (c == ',')) { if (cur_n == n) return s.ToString(); cur_n++; s.Length = 0; pos++; continue; } if (c == '"') quoted = !quoted; else s.Append(c); pos++; } if (cur_n == n) return s.ToString().Trim(); return null; } static private SolutionNode parseNode(StreamReader reader, string sectionTerminator, out bool eof) { eof = false; string line; do { line = reader.ReadLine(); if (line == null) { eof = true; return null; } if (line.Trim() == sectionTerminator) return null; } while (line.Trim().Length == 0); int pos = 0; SolutionNode node = new SolutionNode(); bool quoted = false; char c = '\0'; // Get node name while (pos < line.Length) { c = line[pos]; if (!quoted && (c == '=' || c == '(')) break; if (c == '"') quoted = !quoted; pos++; } node.nodeName = line.Substring(0, pos).Trim(); node.nodeType = NodeType.ntItem; if (pos >= line.Length) { node.nodeType = NodeType.ntSection; } else if (c == '(') { // Get section name int start_pos = ++pos; while (pos < line.Length) { c = line[pos]; pos++; if (!quoted && c == ')') break; if (c == '"') quoted = !quoted; } node.sectionName = line.Substring(start_pos, pos-start_pos-1).Trim(); node.nodeType = NodeType.ntSection; // Skip everything before equals sign while (pos < line.Length && line[pos] != '=') pos++; } // Get item value now if (pos < line.Length) node.nodeValue = line.Substring(pos+1).Trim(); // Read in section contents if (node.nodeType == NodeType.ntSection) { SolutionNode item; bool sectEof; node.sectionItems = new ArrayList(); while ((item = parseNode(reader, "End" + node.nodeName, out sectEof))!=null) node.sectionItems.Add(item); // If we hit EOF than was not a section if (sectEof) throw new ApplicationException("Error parsing solution file"); } return node; } static public SolutionNode parseSolution(StreamReader reader) { string line = reader.ReadLine(); SolutionNode rootNode = new SolutionNode(); rootNode.nodeType = NodeType.ntRoot; rootNode.nodeName = line; rootNode.sectionItems = new ArrayList(); SolutionNode node; bool eof; while ((node = parseNode(reader, null, out eof))!=null) rootNode.sectionItems.Add(node); return rootNode; } private void streamNode(StreamWriter writer, int level) { StringBuilder headLine = new StringBuilder(nodeName); if (sectionName != null) { headLine.Append("(").Append(sectionName).Append(")"); } if (nodeValue != null) headLine.Append(" = ").Append(nodeValue); for (int i = 0; i<level; i++) headLine.Insert(0, '\t'); writer.WriteLine(headLine.ToString()); if (nodeType == NodeType.ntSection) { foreach (SolutionNode node in sectionItems) node.streamNode(writer, level + 1); headLine.Length = 0; for (int i = 0; i<level; i++) headLine.Append('\t'); headLine.Append("End").Append(nodeName); writer.WriteLine(headLine.ToString()); } } static public void streamSolution(StreamWriter writer, SolutionNode rootNode) { writer.WriteLine(rootNode.nodeName); // Version, etc foreach (SolutionNode node in rootNode.sectionItems) node.streamNode(writer, 0); } static public SolutionNode findCreateSectionBefore(SolutionNode parent, string nodeName, string sectionName, bool create, string prevNodeName, string prevSectionName) { foreach(SolutionNode node in parent.sectionItems) { if (node.nodeType == SolutionNode.NodeType.ntSection && node.nodeName == nodeName && node.sectionName == sectionName) { return node; } } if (!create) return null; SolutionNode section = new SolutionNode(); section.nodeType = SolutionNode.NodeType.ntSection; section.nodeName = nodeName; section.sectionName = sectionName; section.sectionItems = new ArrayList(); for(int i=0; i < parent.sectionItems.Count; i++) { SolutionNode node = (SolutionNode)parent.sectionItems[i]; if (node.nodeName == prevNodeName && node.sectionName == prevSectionName) { parent.sectionItems.Insert(i, section); return section; } } parent.sectionItems.Add(section); return section; } static public SolutionNode findCreateValue(SolutionNode parent, string nodeName, string nodeValue) { foreach(SolutionNode node in parent.sectionItems) { if (node.nodeType == SolutionNode.NodeType.ntItem && node.nodeName == nodeName && node.nodeValue == nodeValue) { return node; } } SolutionNode item = new SolutionNode(); item.nodeType = NodeType.ntItem; item.nodeName = nodeName; item.nodeValue = nodeValue; parent.sectionItems.Add(item); return item; } } |