Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine($"Please specify a project file.");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine($"File {args[0]} could not be found.");
                return;
            }

            XDocument xmlDocument;

            using (var stream = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                xmlDocument = XDocument.Load(stream);
            }

            XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003";

            if (xmlDocument.Element(nsSys + "Project") == null)
            {
                Console.WriteLine($"This is not a VS2015 project file.");
                return;
            }

            var projectDefinition = new Project();

            var fileInfo  = new FileInfo(args[0]);
            var directory = fileInfo.Directory;

            Task.WaitAll(_transformationsToApply.Select(
                             t => t.TransformAsync(xmlDocument, directory, projectDefinition))
                         .ToArray());

            AssemblyReferenceTransformation.RemoveExtraAssemblyReferences(projectDefinition);

            var projectFile = fileInfo.FullName;

            if (!SaveBackup(projectFile))
            {
                return;
            }

            var packagesFile = Path.Combine(fileInfo.DirectoryName, "packages.config");

            if (File.Exists(packagesFile))
            {
                if (!RenameFile(packagesFile))
                {
                    return;
                }
            }

            new ProjectWriter().Write(projectDefinition, fileInfo);
        }
Ejemplo n.º 2
0
        private static void ProcessFile(string filePath)
        {
            var file = new FileInfo(filePath);

            if (!Validate(file))
            {
                return;
            }

            XDocument xmlDocument;

            using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                xmlDocument = XDocument.Load(stream);
            }

            XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003";

            if (xmlDocument.Element(nsSys + "Project") == null)
            {
                Console.WriteLine($"This is not a VS2015 project file.");
                return;
            }

            var projectDefinition = new Project();

            var fileInfo  = new FileInfo(filePath);
            var directory = fileInfo.Directory;

            Task.WaitAll(_transformationsToApply.Select(
                             t => t.TransformAsync(xmlDocument, directory, projectDefinition))
                         .ToArray());

            AssemblyReferenceTransformation.RemoveExtraAssemblyReferences(projectDefinition);

            var projectFile = fileInfo.FullName;

            if (!SaveBackup(projectFile))
            {
                return;
            }

            var packagesFile = Path.Combine(fileInfo.DirectoryName, "packages.config");

            if (File.Exists(packagesFile))
            {
                if (!RenameFile(packagesFile))
                {
                    return;
                }
            }

            var nuspecFile = fileInfo.FullName.Replace("csproj", "nuspec");

            if (File.Exists(nuspecFile))
            {
                if (!RenameFile(nuspecFile))
                {
                    return;
                }
            }

            if (Config.RemoveAssemblyInfo)
            {
                var assemblyInfoFiles = new DirectoryInfo(fileInfo.DirectoryName)
                                        .EnumerateFiles("AssemblyInfo.cs", SearchOption.AllDirectories)
                                        .ToArray();
                foreach (var assemblyInfoFile in assemblyInfoFiles)
                {
                    assemblyInfoFile.Delete();
                }
            }

            new ProjectWriter().Write(projectDefinition, fileInfo);
        }
Ejemplo n.º 3
0
        private static Definition.Project ProcessFile(string filePath, IProgress <string> progress)
        {
            var file = new FileInfo(filePath);

            if (!Validate(file, progress))
            {
                return(null);
            }

            XDocument xmlDocument;

            using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                xmlDocument = XDocument.Load(stream);
            }

            XNamespace nsSys = "http://schemas.microsoft.com/developer/msbuild/2003";

            if (xmlDocument.Element(nsSys + "Project") == null)
            {
                progress.Report($"This is not a VS2015 project file.");
                return(null);
            }

            var fileInfo          = new FileInfo(filePath);
            var projectDefinition = new Project
            {
                FilePath = fileInfo
            };

            var directory = fileInfo.Directory;

            Task.WaitAll(_transformationsToApply.Select(
                             t => t.TransformAsync(xmlDocument, directory, projectDefinition, progress))
                         .ToArray());

            AssemblyReferenceTransformation.RemoveExtraAssemblyReferences(projectDefinition);

            var projectFile = fileInfo.FullName;

            if (!SaveBackup(projectFile, progress))
            {
                return(null);
            }

            var packagesFile = Path.Combine(fileInfo.DirectoryName, "packages.config");

            if (File.Exists(packagesFile))
            {
                if (!RenameFile(packagesFile, progress))
                {
                    return(null);
                }
            }

            var nuspecFile = fileInfo.FullName.Replace("csproj", "nuspec");

            if (File.Exists(nuspecFile))
            {
                if (!RenameFile(nuspecFile, progress))
                {
                    return(null);
                }
            }

            return(projectDefinition);
        }