本文整理汇总了C#中Solution.ConvertToFormat方法的典型用法代码示例。如果您正苦于以下问题:C# Solution.ConvertToFormat方法的具体用法?C# Solution.ConvertToFormat怎么用?C# Solution.ConvertToFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solution
的用法示例。
在下文中一共展示了Solution.ConvertToFormat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWrapperSolution
public Solution GetWrapperSolution (IProgressMonitor monitor, string filename)
{
// First of all, check if a solution with the same name already exists
FileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormats (filename, typeof(SolutionEntityItem));
if (formats.Length == 0)
formats = new FileFormat [] { DefaultFileFormat };
Solution tempSolution = new Solution ();
FileFormat solutionFileFormat;
if (formats [0].CanWrite (tempSolution))
solutionFileFormat = formats [0];
else
solutionFileFormat = MonoDevelop.Projects.Formats.MD1.MD1ProjectService.FileFormat;
string solFileName = solutionFileFormat.GetValidFileName (tempSolution, filename);
if (File.Exists (solFileName)) {
return (Solution) Services.ProjectService.ReadWorkspaceItem (monitor, solFileName);
}
else {
// Create a temporary solution and add the project to the solution
tempSolution.SetLocation (Path.GetDirectoryName (filename), Path.GetFileNameWithoutExtension (filename));
SolutionEntityItem sitem = Services.ProjectService.ReadSolutionItem (monitor, filename);
tempSolution.ConvertToFormat (solutionFileFormat, false);
tempSolution.RootFolder.Items.Add (sitem);
tempSolution.CreateDefaultConfigurations ();
tempSolution.Save (monitor);
return tempSolution;
}
}
示例2: SolutionName
public void SolutionName ()
{
int nameChanges = 0;
Solution sol = new Solution ();
sol.NameChanged += delegate {
nameChanges++;
};
string tmp = Path.GetTempPath ();
sol.Name = "test1";
Assert.AreEqual ("test1", sol.Name);
Assert.AreEqual ("test1.sln", (string) sol.FileName);
Assert.AreEqual (1, nameChanges);
sol.Name = "test2";
Assert.AreEqual ("test2", sol.Name);
Assert.AreEqual ("test2.sln", (string) sol.FileName);
Assert.AreEqual (2, nameChanges);
sol.FileName = Path.Combine (tmp, "test3.sln");
Assert.AreEqual ("test3", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test3.sln"), (string) sol.FileName);
Assert.AreEqual (3, nameChanges);
sol.Name = "test4";
Assert.AreEqual ("test4", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test4.sln"), (string) sol.FileName);
Assert.AreEqual (4, nameChanges);
sol.ConvertToFormat (Util.FileFormatMD1, true);
Assert.AreEqual ("test4", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test4.mds"), (string) sol.FileName);
Assert.AreEqual (4, nameChanges);
}
示例3: ProjectName
public void ProjectName ()
{
int nameChanges = 0;
DotNetAssemblyProject prj = new DotNetAssemblyProject ("C#");
prj.FileFormat = Util.FileFormatMSBuild05;
prj.NameChanged += delegate {
nameChanges++;
};
prj.Name = "test1";
Assert.AreEqual ("test1", prj.Name);
Assert.AreEqual ("test1.csproj", (string) prj.FileName);
Assert.AreEqual (1, nameChanges);
prj.Name = "test2";
Assert.AreEqual ("test2", prj.Name);
Assert.AreEqual ("test2.csproj", (string) prj.FileName);
Assert.AreEqual (2, nameChanges);
string fname = Path.Combine (Path.GetTempPath (), "test3.csproj");
prj.FileName = fname;
Assert.AreEqual ("test3", prj.Name);
Assert.AreEqual (fname, (string) prj.FileName);
Assert.AreEqual (3, nameChanges);
prj.Name = "test4";
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
prj.FileFormat = Util.FileFormatMD1;
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.mdp"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
Assert.AreEqual ("MD1", prj.FileFormat.Id);
// Projects inherit the file format from the parent solution
Solution sol = new Solution ();
sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
sol.RootFolder.Items.Add (prj);
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);
// Removing the project from the solution should not restore the old format
sol.RootFolder.Items.Remove (prj);
Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
}
示例4: CheckGenericItemProject
public static void CheckGenericItemProject (string fileFormat)
{
Solution sol = new Solution ();
sol.ConvertToFormat (Services.ProjectService.FileFormats.GetFileFormat (fileFormat), true);
string dir = Util.CreateTmpDir ("generic-item-" + fileFormat);
sol.FileName = Path.Combine (dir, "TestGenericItem");
sol.Name = "TheItem";
GenericItem it = new GenericItem ();
it.SomeValue = "hi";
sol.RootFolder.Items.Add (it);
it.FileName = Path.Combine (dir, "TheItem");
it.Name = "TheItem";
sol.Save (Util.GetMonitor ());
Solution sol2 = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
Assert.AreEqual (1, sol2.Items.Count);
Assert.IsTrue (sol2.Items [0] is GenericItem);
it = (GenericItem) sol2.Items [0];
Assert.AreEqual ("hi", it.SomeValue);
}
示例5: TestLoadSaveSolutionFolders
public static void TestLoadSaveSolutionFolders (string fileFormat)
{
List<string> ids = new List<string> ();
Solution sol = new Solution ();
sol.ConvertToFormat (Services.ProjectService.FileFormats.GetFileFormat (fileFormat), true);
string dir = Util.CreateTmpDir ("solution-folders-" + fileFormat);
sol.FileName = Path.Combine (dir, "TestSolutionFolders");
sol.Name = "TheSolution";
DotNetAssemblyProject p1 = new DotNetAssemblyProject ("C#");
p1.FileName = Path.Combine (dir, "p1");
sol.RootFolder.Items.Add (p1);
string idp1 = p1.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idp1));
Assert.IsFalse (ids.Contains (idp1));
ids.Add (idp1);
SolutionFolder f1 = new SolutionFolder ();
f1.Name = "f1";
sol.RootFolder.Items.Add (f1);
string idf1 = f1.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idf1));
Assert.IsFalse (ids.Contains (idf1));
ids.Add (idf1);
DotNetAssemblyProject p2 = new DotNetAssemblyProject ("C#");
p2.FileName = Path.Combine (dir, "p2");
f1.Items.Add (p2);
string idp2 = p2.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idp2));
Assert.IsFalse (ids.Contains (idp2));
ids.Add (idp2);
SolutionFolder f2 = new SolutionFolder ();
f2.Name = "f2";
f1.Items.Add (f2);
string idf2 = f2.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idf2));
Assert.IsFalse (ids.Contains (idf2));
ids.Add (idf2);
DotNetAssemblyProject p3 = new DotNetAssemblyProject ("C#");
p3.FileName = Path.Combine (dir, "p3");
f2.Items.Add (p3);
string idp3 = p3.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idp3));
Assert.IsFalse (ids.Contains (idp3));
ids.Add (idp3);
DotNetAssemblyProject p4 = new DotNetAssemblyProject ("C#");
p4.FileName = Path.Combine (dir, "p4");
f2.Items.Add (p4);
string idp4 = p4.ItemId;
Assert.IsFalse (string.IsNullOrEmpty (idp4));
Assert.IsFalse (ids.Contains (idp4));
ids.Add (idp4);
sol.Save (Util.GetMonitor ());
Solution sol2 = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
Assert.AreEqual (4, sol2.Items.Count);
Assert.AreEqual (2, sol2.RootFolder.Items.Count);
Assert.AreEqual (typeof(DotNetAssemblyProject), sol2.RootFolder.Items [0].GetType ());
Assert.AreEqual (typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType ());
Assert.AreEqual ("p1", sol2.RootFolder.Items [0].Name);
Assert.AreEqual ("f1", sol2.RootFolder.Items [1].Name);
Assert.AreEqual (idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
Assert.AreEqual (idf1, sol2.RootFolder.Items [1].ItemId, "idf1");
f1 = (SolutionFolder) sol2.RootFolder.Items [1];
Assert.AreEqual (2, f1.Items.Count);
Assert.AreEqual (typeof(DotNetAssemblyProject), f1.Items [0].GetType ());
Assert.AreEqual (typeof(SolutionFolder), f1.Items [1].GetType ());
Assert.AreEqual ("p2", f1.Items [0].Name);
Assert.AreEqual ("f2", f1.Items [1].Name);
Assert.AreEqual (idp2, f1.Items [0].ItemId, "idp2");
Assert.AreEqual (idf2, f1.Items [1].ItemId, "idf2");
f2 = (SolutionFolder) f1.Items [1];
Assert.AreEqual (2, f2.Items.Count);
Assert.AreEqual (typeof(DotNetAssemblyProject), f2.Items [0].GetType ());
Assert.AreEqual (typeof(DotNetAssemblyProject), f2.Items [1].GetType ());
Assert.AreEqual ("p3", f2.Items [0].Name);
Assert.AreEqual ("p4", f2.Items [1].Name);
Assert.AreEqual (idp3, f2.Items [0].ItemId, "idp4");
Assert.AreEqual (idp4, f2.Items [1].ItemId, "idp4");
}
示例6: LoadSolution
//ExtendedProperties
// Per config
// Platform : Eg. Any CPU
// SolutionConfigurationPlatforms
//
SolutionFolder LoadSolution (Solution sol, string fileName, MSBuildFileFormat format, IProgressMonitor monitor)
{
string headerComment;
string version = GetSlnFileVersion (fileName, out headerComment);
ListDictionary globals = null;
SolutionFolder folder = null;
SlnData data = null;
List<Section> projectSections = null;
List<string> lines = null;
FileFormat projectFormat = Services.ProjectService.FileFormats.GetFileFormat (format);
monitor.BeginTask (GettextCatalog.GetString ("Loading solution: {0}", fileName), 1);
//Parse the .sln file
using (StreamReader reader = new StreamReader(fileName)) {
sol.FileName = fileName;
sol.ConvertToFormat (projectFormat, false);
folder = sol.RootFolder;
sol.Version = "0.1"; //FIXME:
data = new SlnData ();
folder.ExtendedProperties [typeof (SlnFileFormat)] = data;
data.VersionString = version;
data.HeaderComment = headerComment;
string s = null;
projectSections = new List<Section> ();
lines = new List<string> ();
globals = new ListDictionary ();
//Parse
while (reader.Peek () >= 0) {
s = GetNextLine (reader, lines).Trim ();
if (String.Compare (s, "Global", StringComparison.OrdinalIgnoreCase) == 0) {
ParseGlobal (reader, lines, globals);
continue;
}
if (s.StartsWith ("Project", StringComparison.Ordinal)) {
Section sec = new Section ();
projectSections.Add (sec);
sec.Start = lines.Count - 1;
int e = ReadUntil ("EndProject", reader, lines);
sec.Count = (e < 0) ? 1 : (e - sec.Start + 1);
continue;
}
if (s.StartsWith ("VisualStudioVersion = ", StringComparison.Ordinal)) {
Version v;
if (Version.TryParse (s.Substring ("VisualStudioVersion = ".Length), out v))
data.VisualStudioVersion = v;
else
monitor.Log.WriteLine ("Ignoring unparseable VisualStudioVersion value in sln file");
}
if (s.StartsWith ("MinimumVisualStudioVersion = ", StringComparison.Ordinal)) {
Version v;
if (Version.TryParse (s.Substring ("MinimumVisualStudioVersion = ".Length), out v))
data.MinimumVisualStudioVersion = v;
else
monitor.Log.WriteLine ("Ignoring unparseable MinimumVisualStudioVersion value in sln file");
}
}
}
monitor.BeginTask("Loading projects ..", projectSections.Count + 1);
Dictionary<string, SolutionItem> items = new Dictionary<string, SolutionItem> ();
List<SolutionItem> sortedList = new List<SolutionItem> ();
foreach (Section sec in projectSections) {
monitor.Step (1);
Match match = ProjectRegex.Match (lines [sec.Start]);
if (!match.Success) {
LoggingService.LogDebug (GettextCatalog.GetString (
"Invalid Project definition on line number #{0} in file '{1}'. Ignoring.",
sec.Start + 1,
fileName));
continue;
}
try {
// Valid guid?
new Guid (match.Groups [1].Value);
} catch (FormatException) {
//Use default guid as projectGuid
LoggingService.LogDebug (GettextCatalog.GetString (
"Invalid Project type guid '{0}' on line #{1}. Ignoring.",
match.Groups [1].Value,
sec.Start + 1));
continue;
}
//.........这里部分代码省略.........
示例7: ReadFile
public object ReadFile (FilePath fileName, bool hasParentSolution, IProgressMonitor monitor)
{
FilePath basePath = fileName.ParentDirectory;
MonoMakefile mkfile = new MonoMakefile (fileName);
string aname = mkfile.GetVariable ("LIBRARY");
if (aname == null) aname = mkfile.GetVariable ("PROGRAM");
try {
ProjectExtensionUtil.BeginLoadOperation ();
if (aname != null) {
// It is a project
monitor.BeginTask ("Loading '" + fileName + "'", 0);
DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
MonoSolutionItemHandler handler = new MonoSolutionItemHandler (project);
ProjectExtensionUtil.InstallHandler (handler, project);
project.Name = Path.GetFileName (basePath);
handler.Read (mkfile);
monitor.EndTask ();
return project;
} else {
string subdirs;
StringBuilder subdirsBuilder = new StringBuilder ();
subdirsBuilder.Append (mkfile.GetVariable ("common_dirs"));
if (subdirsBuilder.Length != 0) {
subdirsBuilder.Append ("\t");
subdirsBuilder.Append (mkfile.GetVariable ("net_2_0_dirs"));
}
if (subdirsBuilder.Length == 0)
subdirsBuilder.Append (mkfile.GetVariable ("SUBDIRS"));
subdirs = subdirsBuilder.ToString ();
if (subdirs != null && (subdirs = subdirs.Trim (' ','\t')) != "")
{
object retObject;
SolutionFolder folder;
if (!hasParentSolution) {
Solution sol = new Solution ();
sol.ConvertToFormat (Services.ProjectService.FileFormats.GetFileFormat ("MonoMakefile"), false);
sol.FileName = fileName;
folder = sol.RootFolder;
retObject = sol;
foreach (string conf in MonoMakefileFormat.Configurations) {
SolutionConfiguration sc = new SolutionConfiguration (conf);
sol.Configurations.Add (sc);
}
} else {
folder = new SolutionFolder ();
folder.Name = Path.GetFileName (Path.GetDirectoryName (fileName));
retObject = folder;
}
subdirs = subdirs.Replace ('\t',' ');
string[] dirs = subdirs.Split (' ');
monitor.BeginTask ("Loading '" + fileName + "'", dirs.Length);
Hashtable added = new Hashtable ();
foreach (string dir in dirs) {
if (added.Contains (dir)) continue;
added.Add (dir, dir);
monitor.Step (1);
if (dir == null) continue;
string tdir = dir.Trim ();
if (tdir == "") continue;
string mfile = Path.Combine (Path.Combine (basePath, tdir), "Makefile");
if (File.Exists (mfile) && CanReadFile (mfile, typeof(SolutionItem))) {
SolutionItem it = (SolutionItem) ReadFile (mfile, true, monitor);
folder.Items.Add (it);
}
}
monitor.EndTask ();
return retObject;
}
}
} finally {
ProjectExtensionUtil.EndLoadOperation ();
}
return null;
}
示例8: GetWrapperSolution
//TODO: find solution that contains the project if possible
public async Task<Solution> GetWrapperSolution (ProgressMonitor monitor, string filename)
{
// First of all, check if a solution with the same name already exists
string solFileName = Path.ChangeExtension (filename, ".sln");
if (File.Exists (solFileName)) {
return (Solution) await Services.ProjectService.ReadWorkspaceItem (monitor, solFileName);
}
else {
// Create a temporary solution and add the project to the solution
SolutionItem sitem = await Services.ProjectService.ReadSolutionItem (monitor, filename);
Solution tempSolution = new Solution ();
tempSolution.FileName = solFileName;
tempSolution.ConvertToFormat (sitem.FileFormat);
tempSolution.RootFolder.Items.Add (sitem);
tempSolution.CreateDefaultConfigurations ();
await tempSolution.SaveAsync (monitor);
return tempSolution;
}
}
示例9: LoadSolution
//ExtendedProperties
// Per config
// Platform : Eg. Any CPU
// SolutionConfigurationPlatforms
//
SolutionFolder LoadSolution (Solution sol, string fileName, MSBuildFileFormat format, IProgressMonitor monitor)
{
string headerComment;
string version = GetSlnFileVersion (fileName, out headerComment);
ListDictionary globals = null;
SolutionFolder folder = null;
SlnData data = null;
List<Section> projectSections = null;
List<string> lines = null;
FileFormat projectFormat = Services.ProjectService.FileFormats.GetFileFormat (format);
monitor.BeginTask (GettextCatalog.GetString ("Loading solution: {0}", fileName), 1);
//Parse the .sln file
using (StreamReader reader = new StreamReader(fileName)) {
sol.FileName = fileName;
sol.ConvertToFormat (projectFormat, false);
folder = sol.RootFolder;
sol.Version = "0.1"; //FIXME:
data = new SlnData ();
folder.ExtendedProperties [typeof (SlnFileFormat)] = data;
data.VersionString = version;
data.HeaderComment = headerComment;
string s = null;
projectSections = new List<Section> ();
lines = new List<string> ();
globals = new ListDictionary ();
//Parse
while (reader.Peek () >= 0) {
s = GetNextLine (reader, lines).Trim ();
if (String.Compare (s, "Global", true) == 0) {
ParseGlobal (reader, lines, globals);
continue;
}
if (s.StartsWith ("Project")) {
Section sec = new Section ();
projectSections.Add (sec);
sec.Start = lines.Count - 1;
int e = ReadUntil ("EndProject", reader, lines);
sec.Count = (e < 0) ? 1 : (e - sec.Start + 1);
continue;
}
}
}
monitor.BeginTask("Loading projects ..", projectSections.Count + 1);
Dictionary<string, SolutionItem> items = new Dictionary<string, SolutionItem> ();
List<SolutionItem> sortedList = new List<SolutionItem> ();
foreach (Section sec in projectSections) {
monitor.Step (1);
Match match = ProjectRegex.Match (lines [sec.Start]);
if (!match.Success) {
LoggingService.LogDebug (GettextCatalog.GetString (
"Invalid Project definition on line number #{0} in file '{1}'. Ignoring.",
sec.Start + 1,
fileName));
continue;
}
try {
// Valid guid?
new Guid (match.Groups [1].Value);
} catch (FormatException) {
//Use default guid as projectGuid
LoggingService.LogDebug (GettextCatalog.GetString (
"Invalid Project type guid '{0}' on line #{1}. Ignoring.",
match.Groups [1].Value,
sec.Start + 1));
continue;
}
string projTypeGuid = match.Groups [1].Value.ToUpper ();
string projectName = match.Groups [2].Value;
string projectPath = match.Groups [3].Value;
string projectGuid = match.Groups [4].Value;
if (projTypeGuid == MSBuildProjectService.FolderTypeGuid) {
//Solution folder
SolutionFolder sfolder = new SolutionFolder ();
sfolder.Name = projectName;
MSBuildProjectService.InitializeItemHandler (sfolder);
MSBuildProjectService.SetId (sfolder, projectGuid);
List<string> projLines = lines.GetRange (sec.Start + 1, sec.Count - 2);
DeserializeSolutionItem (sol, sfolder, projLines);
foreach (string f in ReadFolderFiles (projLines))
//.........这里部分代码省略.........
示例10: CheckGenericItemProject
public static async Task CheckGenericItemProject (MSBuildFileFormat format)
{
Solution sol = new Solution ();
sol.ConvertToFormat (format);
string dir = Util.CreateTmpDir ("generic-item-" + format.Name);
sol.FileName = Path.Combine (dir, "TestGenericItem");
sol.Name = "TheItem";
MonoDevelop.Projects.MSBuild.MSBuildProjectService.RegisterGenericProjectType ("GenericItem", typeof(GenericItem));
GenericItem it = new GenericItem ();
it.SomeValue = "hi";
sol.RootFolder.Items.Add (it);
it.FileName = Path.Combine (dir, "TheItem");
it.Name = "TheItem";
await sol.SaveAsync (Util.GetMonitor ());
Solution sol2 = (Solution) await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), sol.FileName);
Assert.AreEqual (1, sol2.Items.Count);
Assert.IsInstanceOf<GenericItem> (sol2.Items [0]);
it = (GenericItem) sol2.Items [0];
Assert.AreEqual ("hi", it.SomeValue);
}