public ProjectReader(ILogger logger = null, ConversionOptions conversionOptions = null)
 {
     this.logger                  = logger ?? NoopLogger.Instance;
     this.projectCache            = conversionOptions?.ProjectCache ?? Caching.NoProjectCache.Instance;
     this.nuspecReader            = new NuSpecReader(this.logger);
     this.assemblyInfoReader      = new AssemblyInfoReader(this.logger);
     this.projectPropertiesReader = new ProjectPropertiesReader(this.logger);
 }
Example #2
0
        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);
        }
Example #3
0
 public ProjectReader(ILogger logger = null, ConversionOptions conversionOptions = null)
 {
     this.logger                  = logger ?? NoopLogger.Instance;
     this.projectCache            = conversionOptions?.ProjectCache ?? Caching.NoProjectCache.Instance;
     this.nuspecReader            = new NuSpecReader(this.logger);
     this.forceConversion         = conversionOptions?.Force ?? false;
     this.assemblyInfoReader      = new AssemblyInfoReader(this.logger);
     this.projectPropertiesReader = new ProjectPropertiesReader(this.logger, conversionOptions?.UnknownTargetFrameworkCallback);
 }
Example #4
0
        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);
        }
Example #5
0
        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);
        }