public void IsUnsupportedProjectType_ThrowsExceptionIfXDocumentIsNull() { Assert.ThrowsException <ArgumentNullException>(() => { UnsupportedProjectTypes.IsUnsupportedProjectType(null); }); }
public void CheckAnUnsupportedProjectOutputReturnsCorrectResult(string outputType, string testCase, bool expected) { var xmlDocument = CreateTestProject("MyType", outputType); var actual = UnsupportedProjectTypes.IsUnsupportedProjectType(xmlDocument); Assert.AreEqual(expected, actual, $"Failed for {testCase}: expected {expected} but returned {actual}"); }
public void CheckAnUnsupportedProjectTypeReturnsCorrectResult(string guidTypes, string testCase, UnsupportedProjectReason expected) { var xmlDocument = CreateTestProject("ProjectTypeGuids", guidTypes); var actual = UnsupportedProjectTypes.IsUnsupportedProjectType(xmlDocument); Assert.AreEqual(expected, actual, $"Failed for {testCase}: expected {expected} but returned {actual}"); }
public Project Read(string filePath, IProgress <string> progress) { XDocument projectXml; using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { projectXml = XDocument.Load(stream); } // get ProjectTypeGuids and check for unsupported types if (UnsupportedProjectTypes.IsUnsupportedProjectType(projectXml)) { progress.Report("This project type is not supported for conversion."); return(null); } XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003"; if (projectXml.Element(nsSys + "Project") == null) { progress.Report($"This is not a VS2015 project file."); return(null); } var fileInfo = new FileInfo(filePath); var assemblyReferences = LoadAssemblyReferences(projectXml, progress); var projectReferences = LoadProjectReferences(projectXml, progress); var packagesConfigFile = FindPackagesConfigFile(fileInfo, progress); var packageReferences = LoadPackageReferences(projectXml, packagesConfigFile, progress); var includes = LoadFileIncludes(projectXml); var packageConfig = new NuSpecReader().Read(fileInfo, progress); var projectDefinition = new Project { FilePath = fileInfo, AssemblyReferences = assemblyReferences, ProjectReferences = projectReferences, PackageReferences = packageReferences, IncludeItems = includes, PackageConfiguration = packageConfig, PackagesConfigFile = packagesConfigFile, Deletions = Array.Empty <FileSystemInfo>(), AssemblyAttributeProperties = Array.Empty <XElement>() }; ProjectPropertiesReader.PopulateProperties(projectDefinition, projectXml); var assemblyAttributes = new AssemblyInfoReader().Read(projectDefinition, progress); projectDefinition.AssemblyAttributes = assemblyAttributes; return(projectDefinition); }
public Project Read(string filePath, IProgress <string> progress) { XDocument projectXml; using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { projectXml = XDocument.Load(stream); } // get ProjectTypeGuids and check for unsupported types if (UnsupportedProjectTypes.IsUnsupportedProjectType(projectXml)) { progress.Report("This project type is not supported for conversion."); return(null); } XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003"; if (projectXml.Element(nsSys + "Project") == null) { progress.Report($"This is not a VS2015 project file."); return(null); } var fileInfo = new FileInfo(filePath); var assemblyReferences = LoadAssemblyReferences(projectXml, progress); var projectReferences = LoadProjectReferences(projectXml, progress); var packageReferences = LoadPackageReferences(fileInfo, projectXml, progress); var includes = LoadFileIncludes(projectXml); var packageConfig = new NuSpecReader().Read(fileInfo, progress); var projectDefinition = new Project { FilePath = fileInfo, AssemblyReferences = assemblyReferences, ProjectReferences = projectReferences, PackageReferences = packageReferences, IncludeItems = includes, PackageConfiguration = packageConfig }; //todo: change this to use a pure method like the other loaders //probably by collecting properties into a class ProjectPropertiesReader.PopulateProperties(projectDefinition, projectXml); var assemblyAttributes = LoadAssemblyAttributes(fileInfo, projectDefinition.AssemblyName, progress); projectDefinition.AssemblyAttributes = assemblyAttributes; return(projectDefinition); }
public Project Read(FileInfo projectFile) { projectFile = projectFile ?? throw new ArgumentNullException(nameof(projectFile)); var filePath = projectFile.FullName; if (this.projectCache.TryGetValue(filePath, out var projectDefinition)) { return(projectDefinition); } XDocument projectXml; using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { projectXml = XDocument.Load(stream, LoadOptions.SetLineInfo); } var isLegacy = projectXml.Element(Project.XmlLegacyNamespace + "Project") != null; var isModern = projectXml.Element(XNamespace.None + "Project") != null; if (!isModern && !isLegacy) { this.logger.LogWarning("This is not a MSBuild (Visual Studio) project file."); return(null); } var packageConfig = this.nuspecReader.Read(projectFile); projectDefinition = new Project { IsModernProject = isModern, FilePath = projectFile, ProjectDocument = projectXml, PackageConfiguration = packageConfig, Deletions = Array.Empty <FileSystemInfo>(), AssemblyAttributeProperties = Array.Empty <XElement>() }; projectDefinition.ProjectGuid = ReadProjectGuid(projectDefinition); projectDefinition.AssemblyReferences = LoadAssemblyReferences(projectDefinition); projectDefinition.ProjectReferences = LoadProjectReferences(projectDefinition); projectDefinition.PackagesConfigFile = FindPackagesConfigFile(projectFile); projectDefinition.PackageReferences = LoadPackageReferences(projectDefinition); projectDefinition.ItemGroups = LoadFileIncludes(projectDefinition); ProcessProjectReferences(projectDefinition); projectPropertiesReader.Read(projectDefinition); projectDefinition.IntermediateOutputPaths = ReadIntermediateOutputPaths(projectDefinition); var assemblyAttributes = this.assemblyInfoReader.Read(projectDefinition); projectDefinition.AssemblyAttributes = assemblyAttributes; // get ProjectTypeGuids and check for unsupported types if (!this.forceConversion && UnsupportedProjectTypes.IsUnsupportedProjectType(projectDefinition)) { this.logger.LogError("This project type is not supported for conversion."); return(null); } this.projectCache.Add(filePath, projectDefinition); return(projectDefinition); }
public Project Read() { var filePath = ProjectPath.FullName; if (EnableCaching && _cache.TryGetValue(filePath, out var projectDefinition)) { return(projectDefinition); } XDocument projectXml; using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { projectXml = XDocument.Load(stream, LoadOptions.SetLineInfo); } var isLegacy = projectXml.Element(XmlLegacyNamespace + "Project") != null; var isModern = projectXml.Element(XNamespace.None + "Project") != null; if (!isModern && !isLegacy) { ProgressReporter.Report("This is not a MSBuild (Visual Studio) project file."); return(null); } var packageConfig = new NuSpecReader().Read(ProjectPath, ProgressReporter); projectDefinition = new Project { IsModernProject = isModern, FilePath = ProjectPath, ProjectDocument = projectXml, PackageConfiguration = packageConfig, Deletions = Array.Empty <FileSystemInfo>(), AssemblyAttributeProperties = Array.Empty <XElement>() }; // get ProjectTypeGuids and check for unsupported types if (UnsupportedProjectTypes.IsUnsupportedProjectType(projectDefinition)) { ProgressReporter.Report("This project type is not supported for conversion."); return(null); } if (EnableCaching) { _cache.Add(filePath, projectDefinition); } projectDefinition.AssemblyReferences = LoadAssemblyReferences(projectDefinition); projectDefinition.ProjectReferences = LoadProjectReferences(projectDefinition); projectDefinition.PackagesConfigFile = FindPackagesConfigFile(ProjectPath); projectDefinition.PackageReferences = LoadPackageReferences(projectDefinition); projectDefinition.IncludeItems = LoadFileIncludes(projectDefinition); ProcessProjectReferences(projectDefinition); HandleSpecialProjectTypes(projectXml, projectDefinition); ProjectPropertiesReader.PopulateProperties(projectDefinition, projectXml); var assemblyAttributes = new AssemblyInfoReader().Read(projectDefinition, ProgressReporter); projectDefinition.AssemblyAttributes = assemblyAttributes; return(projectDefinition); }