Author: ankit
Date: 2007-04-26 07:36:24 -0400 (Thu, 26 Apr 2007)
New Revision: 76306
Modified:
trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildSolution.cs
trunk/monodevelop/Extras/prj2make-sharp-lib/SlnData.cs
trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003SlnFileFormat.cs
Log:
* SlnFileFormat.cs (WriteFile): Allow writing for non-root combines
which don't have a msbuild combine as parent. Convert any non-msbuild
child projects to msbuild format, and Save all child entries.
* MSBuildFileFormat.cs (.ctor): Remove .ctor with @language parameter.
(WriteFileInternal): Always save updated References.
(ReferenceToXmlElement): Update if element already exists.
* MSBuildSolution.cs (.cctor): IdeApp.ProjectOperations could be null
when invoked from command line.
(HandleAddEntry): Remove call to UpdateProjectReferences.
(ConvertToMSBuild): Simplify. Change the fileformat, if required, and
Save.
* SlnData.cs (.ctor): New constructors for setting the guid.
* VS2003SlnFileFormat.cs, VS2003ProjectFileFormat.cs: Track api changes.
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog 2007-04-26
10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog 2007-04-26
11:36:24 UTC (rev 76306)
@@ -1,3 +1,19 @@
+2007-04-26 Ankit Jain <[EMAIL PROTECTED]>
+
+ * SlnFileFormat.cs (WriteFile): Allow writing for non-root combines
+ which don't have a msbuild combine as parent. Convert any non-msbuild
+ child projects to msbuild format, and Save all child entries.
+ * MSBuildFileFormat.cs (.ctor): Remove .ctor with @language parameter.
+ (WriteFileInternal): Always save updated References.
+ (ReferenceToXmlElement): Update if element already exists.
+ * MSBuildSolution.cs (.cctor): IdeApp.ProjectOperations could be null
+ when invoked from command line.
+ (HandleAddEntry): Remove call to UpdateProjectReferences.
+ (ConvertToMSBuild): Simplify. Change the fileformat, if required, and
+ Save.
+ * SlnData.cs (.ctor): New constructors for setting the guid.
+ * VS2003SlnFileFormat.cs, VS2003ProjectFileFormat.cs: Track api changes.
+
2007-04-19 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* VS2003SlnFileFormat.cs, VS2003ProjectFileFormat.cs: Track api
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
2007-04-26 10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildFileFormat.cs
2007-04-26 11:36:24 UTC (rev 76306)
@@ -46,7 +46,6 @@
{
public class MSBuildFileFormat : IFileFormat
{
- string language;
internal const string ns =
"http://schemas.microsoft.com/developer/msbuild/2003";
static XmlNamespaceManager manager;
@@ -56,11 +55,6 @@
{
}
- public MSBuildFileFormat (string language)
- {
- this.language = language;
- }
-
public string Name {
get { return "Visual Studio .NET 2005"; }
}
@@ -292,17 +286,17 @@
}
}
+ // Always update the project references
+ foreach (ProjectReference pref in
project.ProjectReferences)
+ data.ProjectReferenceElements [pref] =
ReferenceToXmlElement (data, project, pref);
+
//FIXME: Set ActiveConfiguration
-
CleanUpEmptyItemGroups (doc);
-
+
if (newdoc) {
foreach (ProjectFile pfile in
project.ProjectFiles)
data.ProjectFileElements [pfile] =
FileToXmlElement (data, project, pfile);
- foreach (ProjectReference pref in
project.ProjectReferences)
- data.ProjectReferenceElements [pref] =
ReferenceToXmlElement (data, project, pref);
-
XmlElement elem = doc.CreateElement
("Configuration", ns);
data.GlobalConfigElement.AppendChild (elem);
elem.InnerText = "Debug";
@@ -435,7 +429,7 @@
project.Version = "0.1"; //FIXME:
//Default project name
project.Name = Path.GetFileNameWithoutExtension (fname);
- project.FileFormat = new MSBuildFileFormat (lang);
+ project.FileFormat = new MSBuildFileFormat ();
project.ClrVersion = ClrVersion.Net_2_0;
MSBuildData data = new MSBuildData ();
@@ -516,7 +510,6 @@
static void SetupHandlers (DotNetProject project)
{
- //Setup handlers
//References
project.ReferenceRemovedFromProject += new
ProjectReferenceEventHandler (HandleReferenceRemoved);
project.ReferenceAddedToProject += new
ProjectReferenceEventHandler (HandleReferenceAdded);
@@ -594,23 +587,26 @@
{
ReferenceType refType = projectRef.ReferenceType;
- string elemName;
- if (refType == ReferenceType.Project)
- elemName = "ProjectReference";
- else
- elemName = "Reference";
-
XmlDocument doc = d.Document;
- XmlElement elem = doc.CreateElement (elemName, ns);
+ XmlElement elem;
+ if (!d.ProjectReferenceElements.TryGetValue
(projectRef, out elem)) {
+ string elemName;
+ if (refType == ReferenceType.Project)
+ elemName = "ProjectReference";
+ else
+ elemName = "Reference";
- //Add the element to the document
- XmlNode node = doc.SelectSingleNode (String.Format
("/tns:Project/tns:ItemGroup/tns:{0}", elemName), NamespaceManager);
- if (node == null) {
- node = doc.CreateElement ("ItemGroup", ns);
- doc.DocumentElement.AppendChild (node);
- node.AppendChild (elem);
- } else {
- node.ParentNode.AppendChild (elem);
+ elem = doc.CreateElement (elemName, ns);
+
+ //Add the element to the document
+ XmlNode node = doc.SelectSingleNode
(String.Format ("/tns:Project/tns:ItemGroup/tns:{0}", elemName),
NamespaceManager);
+ if (node == null) {
+ node = doc.CreateElement ("ItemGroup",
ns);
+ doc.DocumentElement.AppendChild (node);
+ node.AppendChild (elem);
+ } else {
+ node.ParentNode.AppendChild (elem);
+ }
}
string reference = projectRef.Reference;
@@ -620,9 +616,9 @@
case ReferenceType.Assembly:
reference = AssemblyName.GetAssemblyName
(reference).ToString ();
- AppendChild (elem, "HintPath", ns,
+ EnsureChildValue (elem, "HintPath", ns,
Runtime.FileService.AbsoluteToRelativePath (project.BaseDirectory,
projectRef.Reference));
- AppendChild (elem, "SpecificVersion", ns,
"False");
+ EnsureChildValue (elem, "SpecificVersion", ns,
"False");
break;
case ReferenceType.Project:
Combine c = project.RootCombine;
@@ -638,14 +634,13 @@
EnsureChildValue (elem,
"Project", ns, String.Concat ("{", data.Guid, "}"));
}
- AppendChild (elem, "Name", ns, p.Name);
+ EnsureChildValue (elem, "Name", ns,
p.Name);
}
break;
case ReferenceType.Custom:
break;
}
- //Add the Include attribute
elem.SetAttribute ("Include", reference);
return elem;
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildSolution.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildSolution.cs
2007-04-26 10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/MSBuildSolution.cs
2007-04-26 11:36:24 UTC (rev 76306)
@@ -49,7 +49,10 @@
static MSBuildSolution ()
{
- IdeApp.ProjectOperations.AddingEntryToCombine += new
AddEntryEventHandler (HandleAddEntry);
+ if (IdeApp.ProjectOperations != null)
+ // this is when invoked w/o the gui
+ //FIXME: Replace with a better way to check this
+ IdeApp.ProjectOperations.AddingEntryToCombine
+= new AddEntryEventHandler (HandleAddEntry);
}
public SlnData Data {
@@ -109,20 +112,17 @@
args.FileName = proj.FileName;
} else {
CombineEntry ce =
Services.ProjectService.ReadCombineEntry (args.FileName, monitor);
- ce = ConvertToMSBuild (ce, false);
+ ConvertToMSBuild (ce);
args.FileName = ce.FileName;
-
- if (String.Compare (extn, ".mds", true) == 0)
- UpdateProjectReferences (((Combine)
ce), true);
-
- ce.FileFormat.WriteFile (ce.FileName, ce,
monitor);
+ ce.Save (monitor);
}
}
static void HandleCombineEntryAdded (object sender,
CombineEntryEventArgs e)
{
try {
- ConvertToMSBuild (e.CombineEntry, true);
+ // ReadFile for Sln/MSBuildFileFormat set the
handlers
+ ConvertToMSBuild (e.CombineEntry);
MSBuildSolution rootSln = (MSBuildSolution)
e.CombineEntry.RootCombine;
MSBuildSolution sln = e.CombineEntry as
MSBuildSolution;
@@ -158,50 +158,22 @@
combine.EntryAdded += new CombineEntryEventHandler
(HandleCombineEntryAdded);
}
- internal static CombineEntry ConvertToMSBuild (CombineEntry ce,
bool prompt)
+ internal static void ConvertToMSBuild (CombineEntry ce)
{
- Combine newCombine = ce as Combine;
- CombineEntry ret = ce;
+ MSBuildFileFormat msformat = new MSBuildFileFormat ();
+ if (!msformat.CanReadFile (ce.FileName)) {
+ // Convert
+ ce.FileFormat = msformat;
+ ce.FileName = msformat.GetValidFormatName (ce,
ce.FileName);
- if (newCombine == null) {
- DotNetProject project = ce as DotNetProject;
- if (project == null)
- return ce;
-
- //FIXME: Use MSBuildFileFormat.CanReadFile
instead
- if (String.Compare (Path.GetExtension
(ce.FileName), ".mdp", true) == 0) {
- MSBuildFileFormat fileFormat = new
MSBuildFileFormat (project.LanguageName);
- project.FileFormat = fileFormat;
-
- string newname =
fileFormat.GetValidFormatName (project, project.FileName);
- project.FileName = newname;
- fileFormat.SaveProject (project, new
NullProgressMonitor ());
- }
- } else {
- SlnData slnData = (SlnData)
newCombine.ExtendedProperties [typeof (SlnFileFormat)];
- if (slnData == null) {
- slnData = new SlnData ();
- newCombine.ExtendedProperties [typeof
(SlnFileFormat)] = slnData;
- }
-
- slnData.Guid = Guid.NewGuid ().ToString
().ToUpper ();
-
- if (String.Compare (Path.GetExtension
(newCombine.FileName), ".mds", true) == 0) {
- foreach (CombineEntry e in
newCombine.Entries)
- ConvertToMSBuild (e, false);
-
- newCombine.FileFormat = new
MSBuildFileFormat ();
- newCombine.FileName =
newCombine.FileFormat.GetValidFormatName (newCombine, newCombine.FileName);
- SetHandlers (newCombine, false);
- }
-
- //This is set to ensure that the solution
folder's BaseDirectory
- //(which is derived from .FileName) matches
that of the root
- //combine
- //newCombine.FileName =
newCombine.RootCombine.FileName;
+ // Save will create the required SlnData,
MSBuildData
+ // objects, create the new guids for the
projects _and_ the
+ // solution folders
+ ce.Save (new NullProgressMonitor ());
+ // Writing out again might be required to fix
+ // project references which have changed
(filenames
+ // changed due to the conversion)
}
-
- return ret;
}
internal static void UpdateProjectReferences (Combine c, bool
saveProjects)
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/SlnData.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/SlnData.cs 2007-04-26
10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/SlnData.cs 2007-04-26
11:36:24 UTC (rev 76306)
@@ -41,6 +41,16 @@
List<string> extra; //used by solution folders..
List<string> unknownProjects;
+ public SlnData ()
+ {
+ this.guid = System.Guid.NewGuid ().ToString ().ToUpper
();
+ }
+
+ public SlnData (string guid)
+ {
+ this.guid = guid;
+ }
+
public string Guid {
get { return guid; }
set { guid = value; }
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
2007-04-26 10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/SlnFileFormat.cs
2007-04-26 11:36:24 UTC (rev 76306)
@@ -76,13 +76,12 @@
if (c == null)
return;
- if (c.ParentCombine != null)
- //Not the top most solution
+ if (c.ParentCombine != null &&
c.ParentCombine.FileFormat is MSBuildFileFormat)
+ // Ignore a non-root combine if its parent is a
msbuild solution
+ // Eg. if parent is a mds, then this should get
emitted as the
+ // top level solution
return;
- if (!c.ExtendedProperties.Contains (typeof
(SlnFileFormat)))
- throw new Exception ("Writing only supported
for vs2005 projects (yet)");
-
string tmpfilename = String.Empty;
try {
monitor.BeginTask (GettextCatalog.GetString
("Saving solution: {0}", file), 1);
@@ -121,11 +120,16 @@
sw.WriteLine ("#MonoDevelop");
//Write the projects
- WriteProjects (c, c.RootCombine.BaseDirectory,
sw, monitor);
+ WriteProjects (c, c.BaseDirectory, sw, monitor);
- //Write the lines for unknownProjects
SlnData slnData = (SlnData)
c.ExtendedProperties [typeof (SlnFileFormat)];
- if (slnData != null) {
+ if (slnData == null) {
+ // If a non-msbuild project is being
converted by just
+ // changing the fileformat, then create
the SlnData for it
+ slnData = new SlnData ();
+ c.ExtendedProperties [typeof
(SlnFileFormat)] = slnData;
+ } else {
+ //Write the lines for unknownProjects
foreach (string l in
slnData.UnknownProjects)
sw.WriteLine (l);
}
@@ -183,18 +187,13 @@
List<string> l = null;
if (c == null) {
//Project
- MSBuildData msbData = (MSBuildData)
ce.ExtendedProperties [typeof (MSBuildFileFormat)];
- if (msbData == null)
- //This should not happen as any
.mdp would've been converted to
- //.*proj and so would have this
object
- //FIXME : But can happen for
unsupported project types.. eg. md-unit
- throw new Exception
(String.Format (
- "INTERNAL ERROR:
Project named '{0}', filename = {1}, does not have a 'data' object.",
- ce.Name, ce.FileName));
+ DotNetProject project = ce as
DotNetProject;
+ if (project == null) {
+ monitor.ReportWarning
(GettextCatalog.GetString (
+ "Error saving project
({0}) : Only DotNetProjects can be part of a MSBuild solution. Ignoring.",
ce.Name));
+ continue;
+ }
- l = msbData.Extra;
-
- DotNetProject project =
(DotNetProject)ce;
if (!ProjectTypeGuids.ContainsKey
(project.LanguageName)) {
// FIXME: Should not happen,
temp
monitor.ReportWarning
(GettextCatalog.GetString ("Saving for project {0} not supported. Ignoring.",
@@ -202,18 +201,37 @@
continue;
}
+ IFileFormat ff = project.FileFormat;
+ if (! (ff is MSBuildFileFormat)) {
+ // Convert to a msbuild file
format
+ project.FileFormat = new
MSBuildFileFormat ();
+ project.FileName =
project.FileFormat.GetValidFormatName (project, project.FileName);
+ }
+
+ project.Save (monitor);
+
+ MSBuildData msbData = (MSBuildData)
project.ExtendedProperties [typeof (MSBuildFileFormat)];
+ if (msbData == null)
+ //This should not happen as
project.Save would've added this
+ throw new Exception
(String.Format (
+ "INTERNAL ERROR:
Project named '{0}', filename = {1}, does not have a 'data' object.",
+ project.Name,
project.FileName));
+
+ l = msbData.Extra;
+
writer.WriteLine
(@"Project(""{{{0}}}"") = ""{1}"", ""{2}"", ""{{{3}}}""",
ProjectTypeGuids
[project.LanguageName],
- ce.Name,
-
Runtime.FileService.AbsoluteToRelativePath (baseDirectory, ce.FileName),
+ project.Name,
+
Runtime.FileService.AbsoluteToRelativePath (baseDirectory, project.FileName),
msbData.Guid);
} else {
//Solution
SlnData slnData = (SlnData)
c.ExtendedProperties [typeof (SlnFileFormat)];
- if (slnData == null)
- throw new Exception
(String.Format (
- "INTERNAL ERROR:
Solution named '{0}', filename = {1}, does not have a 'data' object.",
- ce.Name, ce.FileName));
+ if (slnData == null) {
+ // Solution folder
+ slnData = new SlnData ();
+ c.ExtendedProperties [typeof
(SlnFileFormat)] = slnData;
+ }
l = slnData.Extra;
@@ -433,10 +451,10 @@
folder.Version = "0.1"; //FIXME:
folder.FileFormat = new
MSBuildFileFormat ();
- SlnData slnData = new SlnData ();
+ SlnData slnData = new SlnData (
+ projectGuid.Trim (new char []
{'{', '}'}));
folder.ExtendedProperties [typeof
(SlnFileFormat)] = slnData;
- slnData.Guid = projectGuid.Trim (new
char [] {'{', '}'});
slnData.Extra = lines.GetRange
(sec.Start + 1, sec.Count - 2);
entries [projectGuid] = folder;
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
2007-04-26 10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003ProjectFileFormat.cs
2007-04-26 11:36:24 UTC (rev 76306)
@@ -136,7 +136,8 @@
DotNetProject project = ImportCsproj (fileName, false);
// ConvertToMSBuild saves the project for mdp
- return MSBuildSolution.ConvertToMSBuild (project,
false) as DotNetProject;
+ MSBuildSolution.ConvertToMSBuild (project);
+ return project as DotNetProject;
}
}
}
Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003SlnFileFormat.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003SlnFileFormat.cs
2007-04-26 10:00:36 UTC (rev 76305)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/VS2003SlnFileFormat.cs
2007-04-26 11:36:24 UTC (rev 76306)
@@ -27,6 +27,7 @@
//
using MonoDevelop.Core;
+using MonoDevelop.Core.ProgressMonitoring;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Projects;
@@ -129,8 +130,8 @@
internal static Combine ImportSlnAsMSBuild (string fileName)
{
Combine combine = ImportSln (fileName, false);
- MSBuildSolution.ConvertToMSBuild (combine, false);
- MSBuildSolution.UpdateProjectReferences (combine, true);
+ MSBuildSolution.ConvertToMSBuild (combine);
+ combine.Save (new NullProgressMonitor ());
return combine;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches