private IParsedProject GetSelectedProject() { var selectedProjectDirectory = GetSelectedProjectDirectory(); if (selectedProjectDirectory == null) { return(null); } // Fetch the project that lives in that directory and parse it. var projects = GetSolutionProjects(); foreach (Project p in projects) { var projectDirectory = Path.GetDirectoryName(p.FullName); if (projectDirectory.Equals(selectedProjectDirectory, StringComparison.OrdinalIgnoreCase)) { return(ProjectParser.ParseProject(p)); } } // Failed to determine the project. Debug.WriteLine($"Could not find a project in {selectedProjectDirectory}"); return(null); }
public void TestParseProject_ReturnsNullForBadFileExtension() { _projectMock.Setup(p => p.FullName).Returns(@"c:\path\to\project.bad"); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsNull(result); }
public void TestParseProject_ReturnsJsonProjectForXProjectExtensionWithProjectJson() { _projectMock.Setup(p => p.FullName).Returns(@"c:\path\to\project.xproj"); _fileSystemMock.Setup(fs => fs.File.Exists(@"c:\path\to\project.json")).Returns(true); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsInstanceOfType(result, typeof(JsonProject)); }
public void TestParseProject_ReturnsNullForXProjectExtensionMissingProjectJson() { _projectMock.Setup(p => p.FullName).Returns(@"c:\path\to\project.xproj"); _fileSystemMock.Setup(fs => fs.File.Exists(@"c:\path\to\project.json")).Returns(false); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsNull(result); }
public void TestParseProject_ReturnsNullForOldCsprojMissingProjectTypeGuids() { var projectXDocument = new XDocument(new XElement(XName.Get("Project", ProjectParser.MsbuildNamespace))); const string projectFilePath = @"c:\path\to\project.csproj"; _projectMock.Setup(p => p.FullName).Returns(projectFilePath); _fileSystemMock.Setup(fs => fs.XDocument.Load(projectFilePath)).Returns(projectXDocument); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsNull(result); }
public void TestParseProject_ReturnsNullForCoreCsprojWrongSdk() { var projectXDocument = new XDocument( new XElement( XName.Get("Project"), new XAttribute(XName.Get(ProjectParser.SdkAttributeName), "Microsoft.Net.Sdk.Wrong"))); const string projectFilePath = @"c:\path\to\project.csproj"; _projectMock.Setup(p => p.FullName).Returns(projectFilePath); _fileSystemMock.Setup(fs => fs.XDocument.Load(projectFilePath)).Returns(projectXDocument); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsNull(result); }
public void TestParseProject_ReturnsCoreCsprojProjectForValidCoreCsproj() { var projectXDocument = new XDocument( new XElement( XName.Get("Project"), new XAttribute(XName.Get(ProjectParser.SdkAttributeName), ProjectParser.AspNetCoreSdk), new XElement( XName.Get(ProjectParser.PropertyGroupElementName), new XElement(XName.Get(ProjectParser.TargetFrameworkElementName), "TargetFramework")))); const string projectFilePath = @"c:\path\to\project.csproj"; _projectMock.Setup(p => p.FullName).Returns(projectFilePath); _fileSystemMock.Setup(fs => fs.XDocument.Load(projectFilePath)).Returns(projectXDocument); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsInstanceOfType(result, typeof(NetCoreCsprojProject)); }
public void TestParseProject_ReturnsNet4CsprojProjectForOldCsprojWithWebAppProjectTypeGuid() { var projectXDocument = new XDocument( new XElement( XName.Get("Project", ProjectParser.MsbuildNamespace), new XElement( XName.Get(ProjectParser.PropertyGroupElementName, ProjectParser.MsbuildNamespace), new XElement( XName.Get(ProjectParser.PropertyTypeGuidsElementName, ProjectParser.MsbuildNamespace), $"{Guid.Empty};{ProjectParser.WebApplicationGuid}")))); const string projectFilePath = @"c:\path\to\project.csproj"; _projectMock.Setup(p => p.FullName).Returns(projectFilePath); _projectMock.Setup(p => p.Properties.Item("TargetFrameworkMoniker").Value) .Returns(".NETFramework,Version=v4.4.4"); _fileSystemMock.Setup(fs => fs.XDocument.Load(projectFilePath)).Returns(projectXDocument); IParsedDteProject result = ProjectParser.ParseProject(_projectMock.Object); Assert.IsInstanceOfType(result, typeof(Net4CsprojProject)); }
private IParsedProject GetStartupProject() { var sb = SolutionBuild; if (sb == null) { return(null); } var startupProjects = sb.StartupProjects as Array; if (startupProjects == null) { return(null); } string startupProjectFilePath = startupProjects.GetValue(0) as string; if (startupProjectFilePath == null) { return(null); } string projectName = Path.GetFileNameWithoutExtension(startupProjectFilePath); foreach (Project p in _solution.Projects) { if (p.Name == projectName) { return(ProjectParser.ParseProject(p)); } } // The project could not be found. Debug.WriteLine($"Could not find project {startupProjectFilePath}"); return(null); }