Exemple #1
0
    void GenerateSolution(MetabuildProject metabuild, Boolean wince)
    {
        String solutionFile = Path.Combine(generatePath, Path.GetFileNameWithoutExtension(metabuild.projectFile) +
                                           (wince ? ".CE.sln" : ".sln"));

        using (TextWriter writer = new StreamWriter(File.Open(solutionFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite), Encoding.UTF8))
        {
            writer.WriteLine();
            writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 10.00");
            writer.WriteLine("# Visual Studio 2008");
            {
                SolutionProjectGenerator generator = new SolutionProjectGenerator(writer, wince);
                foreach (MetabuildUnit unit in metabuild.units)
                {
                    unit.Visit(generator);
                }
            }
            writer.WriteLine("Global");
            writer.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
            writer.WriteLine("\t\tDebug|Any CPU = Debug|Any CPU");
            writer.WriteLine("\t\tRelease|Any CPU = Release|Any CPU");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
            {
                SolutionProjectConfigGenerator generator = new SolutionProjectConfigGenerator(writer, wince);
                foreach (MetabuildUnit unit in metabuild.units)
                {
                    unit.Visit(generator);
                }
            }
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(SolutionProperties) = preSolution");
            writer.WriteLine("\t\tHideSolutionNode = FALSE");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("EndGlobal");
        }
    }
        public void SolutionFilterFiltersProjects(bool graphBuild)
        {
            using (TestEnvironment testEnvironment = TestEnvironment.Create())
            {
                TransientTestFolder folder            = testEnvironment.CreateFolder(createFolder: true);
                TransientTestFolder classLibFolder    = testEnvironment.CreateFolder(Path.Combine(folder.Path, "ClassLibrary"), createFolder: true);
                TransientTestFolder classLibSubFolder = testEnvironment.CreateFolder(Path.Combine(classLibFolder.Path, "ClassLibrary"), createFolder: true);
                TransientTestFile   classLibrary      = testEnvironment.CreateFile(classLibSubFolder, "ClassLibrary.csproj",
                                                                                   @"<Project>
                  <Target Name=""ClassLibraryTarget"">
                      <Message Text=""ClassLibraryBuilt""/>
                  </Target>
                  </Project>
                    ");

                TransientTestFolder simpleProjectFolder    = testEnvironment.CreateFolder(Path.Combine(folder.Path, "SimpleProject"), createFolder: true);
                TransientTestFolder simpleProjectSubFolder = testEnvironment.CreateFolder(Path.Combine(simpleProjectFolder.Path, "SimpleProject"), createFolder: true);
                TransientTestFile   simpleProject          = testEnvironment.CreateFile(simpleProjectSubFolder, "SimpleProject.csproj",
                                                                                        @"<Project DefaultTargets=""SimpleProjectTarget"">
                  <Target Name=""SimpleProjectTarget"">
                      <Message Text=""SimpleProjectBuilt""/>
                  </Target>
                  </Project>
                    ");
                // Slashes here (and in the .slnf) are hardcoded as backslashes intentionally to support the common case.
                TransientTestFile solutionFile = testEnvironment.CreateFile(simpleProjectFolder, "SimpleProject.sln",
                                                                            @"
                    Microsoft Visual Studio Solution File, Format Version 12.00
                    # Visual Studio Version 16
                    VisualStudioVersion = 16.0.29326.124
                    MinimumVisualStudioVersion = 10.0.40219.1
                    Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""SimpleProject"", ""SimpleProject\SimpleProject.csproj"", ""{79B5EBA6-5D27-4976-BC31-14422245A59A}""
                    EndProject
                    Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""ClassLibrary"", ""..\ClassLibrary\ClassLibrary\ClassLibrary.csproj"", ""{8EFCCA22-9D51-4268-90F7-A595E11FCB2D}""
                    EndProject
                    Global
                        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                            Debug|Any CPU = Debug|Any CPU
                            Release|Any CPU = Release|Any CPU
                            EndGlobalSection
                        GlobalSection(ProjectConfigurationPlatforms) = postSolution
                            {79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                            {79B5EBA6-5D27-4976-BC31-14422245A59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
                            {79B5EBA6-5D27-4976-BC31-14422245A59A}.Release|Any CPU.ActiveCfg = Release|Any CPU
                            {79B5EBA6-5D27-4976-BC31-14422245A59A}.Release|Any CPU.Build.0 = Release|Any CPU
                            {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                            {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
                            {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
                            {8EFCCA22-9D51-4268-90F7-A595E11FCB2D}.Release|Any CPU.Build.0 = Release|Any CPU
                            {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                            {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
                            {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
                            {06A4DD1B-5027-41EF-B72F-F586A5A83EA5}.Release|Any CPU.Build.0 = Release|Any CPU
                        EndGlobalSection
                        GlobalSection(SolutionProperties) = preSolution
                            HideSolutionNode = FALSE
                        EndGlobalSection
                        GlobalSection(ExtensibilityGlobals) = postSolution
                            SolutionGuid = {DE7234EC-0C4D-4070-B66A-DCF1B4F0CFEF}
                        EndGlobalSection
                    EndGlobal
                ");
                TransientTestFile filterFile = testEnvironment.CreateFile(folder, "solutionFilter.slnf",
                                                                          @"
                {
                  ""solution"": {
                    // I'm a comment
                    ""path"": "".\\SimpleProject\\SimpleProject.sln"",
                    ""projects"": [
                    /* ""..\\ClassLibrary\\ClassLibrary\\ClassLibrary.csproj"", */
                      ""SimpleProject\\SimpleProject.csproj"",
                    ]
                    }
                }
                ");
                Directory.GetCurrentDirectory().ShouldNotBe(Path.GetDirectoryName(filterFile.Path));
                if (graphBuild)
                {
                    ProjectCollection projectCollection = testEnvironment.CreateProjectCollection().Collection;
                    MockLogger        logger            = new();
                    projectCollection.RegisterLogger(logger);
                    ProjectGraphEntryPoint entryPoint = new(filterFile.Path, new Dictionary <string, string>());

                    // We only need to construct the graph, since that tells us what would build if we were to build it.
                    ProjectGraph graphFromSolution = new(entryPoint, projectCollection);
                    logger.AssertNoErrors();
                    graphFromSolution.ProjectNodes.ShouldHaveSingleItem();
                    graphFromSolution.ProjectNodes.Single().ProjectInstance.ProjectFileLocation.LocationString.ShouldBe(simpleProject.Path);
                }
                else
                {
                    SolutionFile      solution   = SolutionFile.Parse(filterFile.Path);
                    ILoggingService   mockLogger = CreateMockLoggingService();
                    ProjectInstance[] instances  = SolutionProjectGenerator.Generate(solution, null, null, _buildEventContext, mockLogger);
                    instances.ShouldHaveSingleItem();

                    // Check that dependencies are built, and non-dependencies in the .sln are not.
                    MockLogger logger = new(output);
                    instances[0].Build(targets: null, new List <ILogger> {
                        logger
                    }).ShouldBeTrue();
                    logger.AssertLogContains(new string[] { "SimpleProjectBuilt" });
                    logger.AssertLogDoesntContain("ClassLibraryBuilt");
                }
            }
        }