25 using System.Collections.Generic;
27 using System.Text.RegularExpressions;
30 namespace SiliconStudio.Core.VisualStudio
37 private readonly Guid guid;
54 original.RelativePath,
57 original.VersionControlProperties,
58 original.PlatformProperties)
94 if (solution == null)
throw new ArgumentNullException(
"solution");
95 if (guid == null)
throw new ArgumentNullException(
"guid");
96 if (typeGuid == null)
throw new ArgumentNullException(
"typeGuid");
97 if (name == null)
throw new ArgumentNullException(
"name");
99 this.solution = solution;
101 this.TypeGuid = typeGuid;
103 this.RelativePath = relativePath;
104 this.ParentGuid = parentGuid;
118 foreach (var child
in Children)
121 foreach (var subchild
in child.AllDescendants)
123 yield
return subchild;
133 public bool IsSolutionFolder
137 return TypeGuid == KnownProjectTypeGuid.SolutionFolder;
149 if (IsSolutionFolder)
151 foreach (var project
in solution.Projects)
153 if (project.ParentGuid == guid)
154 yield
return project;
170 if (ParentProject != null)
172 yield
return ParentProject;
175 if (sections.Contains(
"ProjectDependencies"))
177 foreach (
PropertyItem propertyLine
in sections[
"ProjectDependencies"].Properties)
179 string dependencyGuid = propertyLine.Name;
180 yield
return FindProjectInContainer(
182 "Cannot find one of the dependency of project '{0}'.\nProject guid: {1}\nDependency guid: {2}\nReference found in: ProjectDependencies section of the solution file",
192 if (!
File.Exists(FullPath))
195 "Cannot detect dependencies of projet '{0}' because the project file cannot be found.\nProject full path: '{1}'",
200 var docVisualC =
new XmlDocument();
201 docVisualC.Load(FullPath);
203 foreach (XmlNode xmlNode
in docVisualC.SelectNodes(
@"//ProjectReference"))
205 string dependencyGuid = xmlNode.Attributes[
"ReferencedProjectIdentifier"].Value;
206 string dependencyRelativePathToProject;
207 XmlNode relativePathToProjectNode = xmlNode.Attributes[
"RelativePathToProject"];
208 if (relativePathToProjectNode != null)
210 dependencyRelativePathToProject = relativePathToProjectNode.Value;
214 dependencyRelativePathToProject =
"???";
216 yield
return FindProjectInContainer(
218 "Cannot find one of the dependency of project '{0}'.\nProject guid: {1}\nDependency guid: {2}\nDependency relative path: '{3}'\nReference found in: ProjectReference node of file '{4}'",
222 dependencyRelativePathToProject,
229 if (!
File.Exists(FullPath))
232 "Cannot detect dependencies of projet '{0}' because the project file cannot be found.\nProject full path: '{1}'",
237 foreach (
string line
in File.ReadAllLines(FullPath))
239 var regex =
new Regex(
"^\\s*\"OutputProjectGuid\" = \"\\d*\\:(?<PROJECTGUID>.*)\"$");
240 Match match = regex.Match(line);
243 string dependencyGuid = match.Groups[
"PROJECTGUID"].Value.Trim();
244 yield
return FindProjectInContainer(
246 "Cannot find one of the dependency of project '{0}'.\nProject guid: {1}\nDependency guid: {2}\nReference found in: OutputProjectGuid line of file '{3}'",
260 PropertyItem propertyItem = sections[
"WebsiteProperties"].Properties[
"ProjectReferences"];
261 string value = propertyItem.Value;
262 if (value.StartsWith(
"\""))
263 value = value.Substring(1);
264 if (value.EndsWith(
"\""))
265 value = value.Substring(0, value.Length - 1);
267 foreach (
string dependency
in value.Split(
';'))
269 if (dependency.Trim().Length > 0)
271 string[] parts = dependency.Split(
'|');
272 string dependencyGuid = parts[0];
273 string dependencyName = parts[1];
274 yield
return FindProjectInContainer(
276 "Cannot find one of the dependency of project '{0}'.\nProject guid: {1}\nDependency guid: {2}\nDependency name: {3}\nReference found in: ProjectReferences line in WebsiteProperties section of the solution file",
284 else if (!IsSolutionFolder)
286 if (!
File.Exists(FullPath))
289 "Cannot detect dependencies of projet '{0}' because the project file cannot be found.\nProject full path: '{1}'",
294 var docManaged =
new XmlDocument();
295 docManaged.Load(FullPath);
297 var xmlManager =
new XmlNamespaceManager(docManaged.NameTable);
298 xmlManager.AddNamespace(
"prefix",
"http://schemas.microsoft.com/developer/msbuild/2003");
300 foreach (XmlNode xmlNode
in docManaged.SelectNodes(
@"//prefix:ProjectReference", xmlManager))
302 string dependencyGuid = xmlNode.SelectSingleNode(
@"prefix:Project", xmlManager).InnerText.Trim();
303 string dependencyName = xmlNode.SelectSingleNode(
@"prefix:Name", xmlManager).InnerText.Trim();
304 yield
return FindProjectInContainer(
306 "Cannot find one of the dependency of project '{0}'.\nProject guid: {1}\nDependency guid: {2}\nDependency name: {3}\nReference found in: ProjectReference node of file '{4}'",
333 public string FullPath
337 return Path.Combine(Path.GetDirectoryName(solution.FullPath), RelativePath);
349 if (ParentGuid == Guid.Empty)
352 return FindProjectInContainer(
354 "Cannot find the parent folder of project '{0}'. \nProject guid: {1}\nParent folder guid: {2}",
365 public Guid ParentGuid {
get; set; }
371 public string FullName
375 if (ParentProject != null)
377 return ParentProject.FullName +
@"\" + Name;
399 public string Name {
get; set; }
409 return platformProperties;
429 public Guid TypeGuid {
get; set; }
435 public string RelativePath {
get; set; }
445 return versionControlProperties;
451 return string.Format(
"Project '{0}'", FullName);
454 private Project FindProjectInContainer(Guid projectGuidToFind,
string errorMessageFormat, params
object[] errorMessageParams)
456 Project project = solution.Projects.FindByGuid(projectGuidToFind);
464 private Project FindProjectInContainer(
string projectGuidToFind,
string errorMessageFormat, params
object[] errorMessageParams)
466 return FindProjectInContainer(Guid.Parse(projectGuidToFind), errorMessageFormat, errorMessageParams);
Project(Solution solution, Project original)
Initializes a new instance of the Project class.
A project referenced by a VisualStudio solution.
static readonly Guid WebProject
static readonly Guid Setup
A key/value pair used by PropertyItemCollection
A collection of PropertyItem
Project(Solution solution, Guid guid, Guid typeGuid, string name, string relativePath, Guid parentGuid, IEnumerable< Section > projectSections, IEnumerable< PropertyItem > versionControlLines, IEnumerable< PropertyItem > projectConfigurationPlatformsLines)
Initializes a new instance of the Project class.
override string ToString()
static readonly Guid VisualC