Ejemplo n.º 1
0
        public void ParseNullTest()
        {
            MSBuildSolutionParser solutionParser = new MSBuildSolutionParser();

            Assert.Throws <ArgumentNullException>(
                delegate
            {
                solutionParser.Parse(null);
            });
        }
        private HashSet <PackageReference> GetInstalledPackageReferencesFromSolutionFile(string solutionFileFullPath)
        {
            ISolutionParser solutionParser;

            if (EnvironmentUtility.IsMonoRuntime)
            {
                solutionParser = new XBuildSolutionParser();
            }
            else
            {
                solutionParser = new MSBuildSolutionParser();
            }

            var installedPackageReferences    = new HashSet <PackageReference>(new PackageReferenceComparer());
            IEnumerable <string> projectFiles = Enumerable.Empty <string>();

            try
            {
                projectFiles = solutionParser.GetAllProjectFileNames(solutionFileFullPath);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                //if (ex.InnerException is InvalidProjectFileException)
                //{
                //    return GetPackageReferencesInDirectory(Path.GetDirectoryName(solutionFileFullPath));
                //}

                throw;
            }

            foreach (var projectFile in projectFiles)
            {
                if (!File.Exists(projectFile))
                {
                    Console.WriteWarning(LocalizedResourceManager.GetString("RestoreCommandProjectNotFound"), projectFile);
                    continue;
                }

                string projectConfigFilePath = Path.Combine(
                    Path.GetDirectoryName(projectFile),
                    Constants.PackageReferenceFile);

                string projectName = Path.GetFileNameWithoutExtension(projectFile);

                CommandLineHelper.AddRange(installedPackageReferences, GetInstalledPackageReferences(projectConfigFilePath));
            }

            return(installedPackageReferences);
        }
Ejemplo n.º 3
0
        private void RestorePackagesForSolution(IFileSystem packagesFolderFileSystem, string solutionFileFullPath)
        {
            ISolutionParser solutionParser;

            if (EnvironmentUtility.IsMonoRuntime)
            {
                solutionParser = new XBuildSolutionParser();
            }
            else
            {
                solutionParser = new MSBuildSolutionParser();
            }
            var solutionDirectory = Path.GetDirectoryName(solutionFileFullPath);

            // restore packages for the solution
            var solutionConfigFilePath = Path.Combine(
                solutionDirectory,
                NuGetConstants.NuGetSolutionSettingsFolder,
                Constants.PackageReferenceFile);

            RestorePackagesFromConfigFile(solutionConfigFilePath, packagesFolderFileSystem);

            // restore packages for projects
            var packageReferences = new HashSet <PackageReference>();

            foreach (var projectFile in solutionParser.GetAllProjectFileNames(FileSystem, solutionFileFullPath))
            {
                if (!FileSystem.FileExists(projectFile))
                {
                    Console.WriteWarning(LocalizedResourceManager.GetString("RestoreCommandProjectNotFound"), projectFile);
                    continue;
                }

                string projectConfigFilePath = Path.Combine(
                    Path.GetDirectoryName(projectFile),
                    Constants.PackageReferenceFile);

                string projectName = Path.GetFileNameWithoutExtension(projectFile);

                packageReferences.AddRange(GetPackageReferences(projectConfigFilePath, projectName));
            }

            InstallPackages(packagesFolderFileSystem, packageReferences);
        }
Ejemplo n.º 4
0
        public void ParseTest()
        {
            string[] testProjectFiles = new string[]
            {
                Path.Combine(Path.GetTempPath(), "TestProject.csproj")
            };

            MSBuildSolutionParser       solutionParser = new MSBuildSolutionParser();
            ReadOnlyCollection <string> projectFiles   = solutionParser.Parse(_testSolutionFile);

            Assert.AreEqual(testProjectFiles.Length, projectFiles.Count, "Unexpected number of project files.");

            foreach (string testProjectFile in testProjectFiles)
            {
                Assert.IsTrue(
                    projectFiles.Contains(testProjectFile),
                    "Test project file {0} was not included in the project file list.",
                    testProjectFile);
            }
        }
        public void MSBuildSolutionParserTest()
        {
            if (EnvironmentUtility.IsMonoRuntime)
            {
                return;
            }

            // Arrange
            var fileSystem = new MockFileSystem(@"c:\root");

            fileSystem.AddFile("a.sln",
                               @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""ConsoleApplication1"", ""ConsoleApplication1\ConsoleApplication1.csproj"", ""{034F35C6-790F-4521-9F7C-78C7BC873D75}""
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Solution Items"", ""Solution Items"", ""{991B31D1-9B1A-4547-81C2-B1133753EDAA}""
	ProjectSection(SolutionItems) = preProject
		TextFile1.txt = TextFile1.txt
	EndProjectSection
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""NewFolder1"", ""NewFolder1"", ""{80CA2398-315E-4C1C-AC79-D25E4AD99A6B}""
	ProjectSection(SolutionItems) = preProject
		TextFile2.txt = TextFile2.txt
	EndProjectSection
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""NewFolder2"", ""NewFolder2"", ""{9C49C3BE-EC45-42C3-8A4A-D5942E665385}""
EndProject
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""ClassLibrary1"", ""ClassLibrary1\ClassLibrary1.csproj"", ""{85892561-23F3-413D-86D2-14272C78CB45}""
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{034F35C6-790F-4521-9F7C-78C7BC873D75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{034F35C6-790F-4521-9F7C-78C7BC873D75}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{034F35C6-790F-4521-9F7C-78C7BC873D75}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{034F35C6-790F-4521-9F7C-78C7BC873D75}.Release|Any CPU.Build.0 = Release|Any CPU
		{85892561-23F3-413D-86D2-14272C78CB45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{85892561-23F3-413D-86D2-14272C78CB45}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{85892561-23F3-413D-86D2-14272C78CB45}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{85892561-23F3-413D-86D2-14272C78CB45}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(NestedProjects) = preSolution
		{9C49C3BE-EC45-42C3-8A4A-D5942E665385} = {80CA2398-315E-4C1C-AC79-D25E4AD99A6B}
		{85892561-23F3-413D-86D2-14272C78CB45} = {9C49C3BE-EC45-42C3-8A4A-D5942E665385}
	EndGlobalSection
EndGlobal");

            // Act
            var solutionParser = new MSBuildSolutionParser();
            var projects       = solutionParser.GetAllProjectFileNames(fileSystem, "a.sln").ToList();

            projects.Sort();

            // Assert
            Assert.Equal(
                new[] {
                @"c:\root\ClassLibrary1\ClassLibrary1.csproj",
                @"c:\root\ConsoleApplication1\ConsoleApplication1.csproj"
            },
                projects);
        }
        public void ParseNullTest()
        {
            MSBuildSolutionParser solutionParser = new MSBuildSolutionParser();

            Assert.Throws(typeof(ArgumentNullException), () => solutionParser.Parse(null));
        }
Ejemplo n.º 7
0
        public void ParseNullTest()
        {
            MSBuildSolutionParser solutionParser = new MSBuildSolutionParser();

            solutionParser.Parse(null);
        }
        private HashSet<PackageReference> GetInstalledPackageReferencesFromSolutionFile(string solutionFileFullPath)
        {
            ISolutionParser solutionParser;
            if (EnvironmentUtility.IsMonoRuntime)
            {
                solutionParser = new XBuildSolutionParser();
            }
            else
            {
                solutionParser = new MSBuildSolutionParser();
            }

            var installedPackageReferences = new HashSet<PackageReference>(new PackageReferenceComparer());
            IEnumerable<string> projectFiles = Enumerable.Empty<string>();
            try
            {
                projectFiles = solutionParser.GetAllProjectFileNames(solutionFileFullPath);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                //if (ex.InnerException is InvalidProjectFileException)
                //{
                //    return GetPackageReferencesInDirectory(Path.GetDirectoryName(solutionFileFullPath));
                //}

                throw;
            }

            foreach (var projectFile in projectFiles)
            {
                if (!File.Exists(projectFile))
                {
                    Console.WriteWarning(LocalizedResourceManager.GetString("RestoreCommandProjectNotFound"), projectFile);
                    continue;
                }

                string projectConfigFilePath = Path.Combine(
                    Path.GetDirectoryName(projectFile),
                    Constants.PackageReferenceFile);

                string projectName = Path.GetFileNameWithoutExtension(projectFile);

                CommandLineHelper.AddRange(installedPackageReferences, GetInstalledPackageReferences(projectConfigFilePath));
            }

            return installedPackageReferences;
        }