private void WriteHeader(VisualStudioSolution solution, StringBuilder sb)
 {
     sb.AppendLine($"{SolutionConstants.FormatVersionPrefix} {solution.FormatVersion}");
     sb.AppendLine($"{SolutionConstants.VisualStudioPrefix} {solution.VisualStudio}");
     sb.AppendLine($"{SolutionConstants.VisualStudioVersionPrefix} {solution.VisualStudioVersion}");
     sb.AppendLine($"{SolutionConstants.MinimumVisualStudioPrefix} {solution.MinimumVisualStudioVersion}");
 }
Beispiel #2
0
        private static void AutoIndentTest(VisualStudioSolution solution, string typedText, string expectedText)
        {
            var doc = solution.OpenItem("AutoIndent", "server.js");

            doc.MoveCaret(1, 1);
            doc.Invoke(() => doc.TextView.Caret.EnsureVisible());
            doc.SetFocus();

            Keyboard.Type(typedText);

            string actual = null;

            for (int i = 0; i < 100; i++)
            {
                actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                if (expectedText == actual)
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
            Assert.AreEqual(expectedText, actual);

            solution.App.Dte.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo);
        }
Beispiel #3
0
        public void Removing_Solution_Folder_Removes_Children()
        {
            var solution = VisualStudioSolution.Create(@"c:\TestProject\Test.sln", "Test", false);

            solution.SaveEnabled = false;

            var startupProject = new TestProject("c:\\TestProject\\Project1\\Project.csproj");

            solution.AddItem(startupProject);

            solution.StartupProject = startupProject;

            var folder = solution.AddItem(SolutionFolder.Create("SubFolder"));

            solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project1.csproj"), folder);
            solution.AddItem(new TestProject("c:\\TestProject\\Project1\\Project2.csproj"), folder);

            Assert.Equal(3, solution.Projects.Count());
            Assert.Equal(4, solution.Model.Projects.Count);

            solution.RemoveItem(folder);
            Assert.Equal(1, solution.Projects.Count());
            Assert.Equal(1, solution.Model.Projects.Count);

            Assert.Equal(startupProject, solution.Projects.FirstOrDefault());
        }
Beispiel #4
0
 DotnetMSBuild(
     ProduceRepository repository,
     VisualStudioSolution sln,
     string target)
 {
     DotnetMSBuild(repository, sln, new [] { target });
 }
Beispiel #5
0
        public static object GetTargets(IParameters parameters)
        {
            var git = new GitCheckout {
                Repository = @"C:\Users\Public\Documents\Development\BigSolution.git",
                Directory  = "one"
            };
            var solution = new VisualStudioSolution {
                SolutionPath = git.Files["BigSolution.sln"]
            };
            var webProject  = solution.Projects[parameters.Default("proj", "BigSolution")];
            var serviceName = parameters.Default("svc", "BigWindowsService");
            var service     = solution.Projects[serviceName];

            return(new {
                WebSite = new Iis7WebSite {
                    Directory = webProject.ProjectDirectory,
                    Name = "BigWebSite",
                    Port = 5001
                },
                Tests = new NUnitTests {
                    DllPaths = solution.Projects.Select(p => p.OutputFile)
                },
                Service = new WindowsService {
                    BinaryPath = service.OutputFile,
                    Name = serviceName,
                    DisplayName = "Big Windows Service",
                    Description = "a big windows service demonstrating the bounce build framework"
                },
                Zip = new ZipFile {
                    Directory = webProject.WhenBuilt(() => Path.GetDirectoryName(webProject.OutputFile.Value)),
                    ZipFileName = "web.zip"
                },
            });
        }
Beispiel #6
0
            public static object GetTargets(IParameters parameters)
            {
                var sol = new VisualStudioSolution {
                    SolutionPath = "stuff.sln"
                };

                var env = parameters.Required <string>("env").Switch(
                    "test", Print(sol.Projects["cats"].OutputFile),
                    "stage", Print("this is test"),
                    "live", Print("this is test"));

                var one = new PrintTask(Output)
                {
                    Description = "*------------*one"
                };
                var two = new PrintTask(Output)
                {
                    Description = "*------------*two"
                };

                return(new {
                    One = one,
                    Two = two,
                    Three = env,
                });
            }
Beispiel #7
0
 FindLocalBuildableProjects(ProduceRepository repository, VisualStudioSolution sln) =>
 sln.ProjectReferences
 .Where(r =>
        r.TypeId == VisualStudioProjectTypeIds.CSharp ||
        r.TypeId == VisualStudioProjectTypeIds.CSharpNew)
 .Where(r => PathExtensions.IsDescendantOf(r.AbsoluteLocation, repository.Path))
 .ToList();
Beispiel #8
0
        Build(ProduceRepository repository, string slnPath)
        {
            if (slnPath == null)
            {
                return;
            }

            var sln = new VisualStudioSolution(slnPath);

            var projs = FindLocalBuildableProjects(repository, sln);

            var frameworksByProj =
                projs.ToDictionary(p => p, p => p.GetProject().AllTargetFrameworks.ToList());

            var allFrameworks =
                frameworksByProj.Values
                .SelectMany(list => list)
                .Distinct();

            foreach (var framework in allFrameworks)
            {
                var projsTargetingThisFramework = projs.Where(p => frameworksByProj[p].Contains(framework)).ToList();
                Build(repository, sln, projsTargetingThisFramework, framework);
            }
        }
Beispiel #9
0
        Build(
            ProduceRepository repository,
            VisualStudioSolution sln,
            IList <VisualStudioSolutionProjectReference> projs,
            string framework)
        {
            var properties = new Dictionary <string, String>()
            {
                { "TargetFramework", framework },
            };

            var targets = projs.Select(p => $"{p.MSBuildTargetName}:Publish");

            using (LogicalOperation.Start($"Building .NET for {framework}"))
            {
                var isNetFramework = Regex.IsMatch(framework, @"^net\d+$");

                if (isNetFramework && !CanBuildNetFramework)
                {
                    Trace.TraceInformation("This system can't build for .NET Framework");
                    return;
                }

                if (isNetFramework && BuildNetFrameworkUsingMSBuild)
                {
                    MSBuild(repository, sln, properties, targets);
                    return;
                }

                DotnetMSBuild(repository, sln, properties, targets);
            }
        }
Beispiel #10
0
        MSBuild(
            ProduceRepository repository,
            VisualStudioSolution sln,
            IDictionary <string, string> properties,
            IEnumerable <string> targets)
        {
            Guard.NotNull(repository, nameof(repository));
            Guard.NotNull(sln, nameof(sln));
            Guard.NotNull(properties, nameof(properties));
            Guard.NotNull(targets, nameof(targets));

            var args = new List <string>()
            {
                "/nr:false",
                "/v:m",
            };

            args.AddRange(properties.Select(p => $"/p:{p.Key}=\"{p.Value}\""));
            args.AddRange(targets.Select(t => $"/t:{t}"));

            if (ProcessExtensions.ExecuteAny(true, true, repository.Path, "msbuild", args.ToArray()) != 0)
            {
                throw new UserException("Failed");
            }
        }
        private void CreateProjectConfigurationPlatforms(VisualStudioSolution solution, Guid projectId)
        {
            var solutionConfigurationPlatforms = solution.Global.Sections.FirstOrDefault(x => x.Name.Equals("SolutionConfigurationPlatforms"));

            if (solutionConfigurationPlatforms == null)
            {
                return;
            }

            var projectConfigurationPlatforms = solution.Global.Sections.FirstOrDefault(x => x.Name.Equals("ProjectConfigurationPlatforms"));

            if (projectConfigurationPlatforms == null)
            {
                var index = solution.Global.Sections.IndexOf(solutionConfigurationPlatforms);

                projectConfigurationPlatforms = new GlobalSection
                {
                    Name        = "ProjectConfigurationPlatforms",
                    SectionType = "postSolution"
                };

                solution.Global.Sections.Insert(index + 1, projectConfigurationPlatforms);
            }

            projectConfigurationPlatforms.Items.AddRange(
                solutionConfigurationPlatforms.Items.Select(x => new GlobalSectionItem
            {
                Name  = $"{projectId.ToString("B").ToUpperInvariant()}.{x.Name}",
                Value = x.Value
            }
                                                            ));
        }
        private VisualStudioSolutionProject ParseProject(VisualStudioSolution solution, string projectLine)
        {
            var project = new VisualStudioSolutionProject {
                Solution = solution
            };
            var matches = Regex.Match(projectLine, SolutionConstants.ProjectRegex);

            project.TypeGuid    = new Guid(matches.Groups["typeguid"].Value);
            project.Name        = matches.Groups["name"].Value;
            project.FileName    = matches.Groups["filename"].Value;
            project.ProjectGuid = new Guid(matches.Groups["projectguid"].Value);

            string str;

            while ((str = ReadLine()) != null)
            {
                if (str.Equals("EndProject"))
                {
                    return(project);
                }
                else if (str.StartsWith("ProjectSection("))
                {
                    project.Sections.Add(ParseProjectSection(str));
                }
                else
                {
                    throw new Exception($"Unexpected line in project: {str}");
                }
            }
            return(project);
        }
Beispiel #13
0
        public override IGeneratorCommandResult Run()
        {
            string                      projectFileName = FileSystem.GetFileName(this.Parameters.Project);
            VisualStudioParser          parser          = new();
            VisualStudioSolutionProject project         = parser.ParseProject(this.Parameters.Project);

            if (project == null || project.Id == Guid.Empty)
            {
                VisualStudioSolution solution = parser.ParseSolution(this.Parameters.Solution);
                project = solution?.Projects.FirstOrDefault(x => x.Path.EndsWith(projectFileName)) ?? project;
            }
            if (project != null && project.Id == Guid.Empty)
            {
                project.Id = Guid.NewGuid();
                parser.SetProjectGuid(this.Parameters.Project, project.Id);
            }

            if (project == null || project.Id == Guid.Empty)
            {
                Logger.Warning($"Can not read project id. No solution for project '{this.Parameters.Project}' found. Automatic file cleanup deactivated!");
                return(this.Success());
            }
            this.resolver.Get <IEnvironment>().OutputId = project.Id;

            return(this.Success().ForceRerunOnAsync());
        }
Beispiel #14
0
        DotnetMSBuild(
            ProduceRepository repository,
            VisualStudioSolution sln,
            IEnumerable <string> targets)
        {
            var properties = new Dictionary <string, string>();

            DotnetMSBuild(repository, sln, properties, targets);
        }
        public void BuildsOutputFileOfFirstProject()
        {
            UnzipTestSolution();

            var solution = new VisualStudioSolution { SolutionPath = new ImmediateValue<string>(Path.Combine(SolutionUnzipDirectory, @"TestSolution\TestSolution.sln")) };

            solution.Build();

            Assert.That(File.Exists(solution.Projects["TestSolution"].OutputFile.Value));
        }
        public void Save(VisualStudioSolution solution)
        {
            var sb = new StringBuilder();

            sb.AppendLine();
            WriteHeader(solution, sb);
            WriteProjects(solution, sb);
            WriteGlobal(solution, sb);

            _fileReaderWriter.WriteFile(solution.Filename, sb.ToString(), Encoding.UTF8);
        }
            public void BuildsTheSolution()
            {
                var builder = new VisualStudioSolution();

                builder._header   = new StringBuilder("A");
                builder._projects = new StringBuilder("B");
                builder._global   = new StringBuilder("C");
                var solution = builder.ToString();

                solution.ShouldEqual("ABC");
            }
Beispiel #18
0
        private VisualStudioSolution OpenVisualStudioSolution(string filename)
        {
            var solution = VisualStudioSolution.Deserialize(filename, Terminal.HandleException);

            if (solution == null)
            {
                FileOpenFailed("Visual Studio Solution", filename);
            }

            return(solution);
        }
        private void WriteGlobal(VisualStudioSolution solution, StringBuilder sb)
        {
            sb.AppendLine("Global");

            foreach (var globalSection in solution.Global.Sections)
            {
                WriteGlobalSection(sb, globalSection);
            }

            sb.AppendLine("EndGlobal");
        }
        public void CanAccessProjectsBeforeSolutionExists()
        {
            DeleteTestSolution();

            var solution = new VisualStudioSolution {SolutionPath = new ImmediateValue<string>(Path.Combine(SolutionUnzipDirectory, @"TestSolution\TestSolution.sln"))};

            var outputFiles = solution.Projects.Select(p => p.OutputFile);

            UnzipTestSolution();

            Assert.That(outputFiles.Select(o => o.Value).ToArray(), Is.EquivalentTo(new [] {@"TestSolution\TestSolution\TestSolution\bin\Debug\TestSolution.dll"}));
        }
Beispiel #21
0
        Restore(ProduceRepository repository, string slnPath)
        {
            if (slnPath == null)
            {
                return;
            }

            var sln = new VisualStudioSolution(slnPath);

            using (LogicalOperation.Start("Restoring NuGet packages"))
                Dotnet(repository, "restore", sln);
        }
Beispiel #22
0
 DeleteNuGitFolders(VisualStudioSolution sln)
 {
     Guard.NotNull(sln, nameof(sln));
     while (true)
     {
         var folder = sln.SolutionFolders.FirstOrDefault(f => IsNuGitFolder(f.Name));
         if (folder == null)
         {
             break;
         }
         sln.DeleteSolutionFolder(folder);
     }
 }
        public void Call_WithNormalProject()
        {
            var solution = new VisualStudioSolution();

            var solutionProject = new VisualStudioSolutionProject();

            solutionProject.Solution = solution;
            var project = visualStudioProjectGenerator.CreateNewProject(solutionProject, "", "", "");

            visualStudioProjectWriter.WriteProject("file", solutionProject);

            mockFileReaderWriter.Received(1).WriteFile(Arg.Any <string>(), Arg.Any <MemoryStream>());
        }
        public void Call_With_SolutionFolder()
        {
            var solution = new VisualStudioSolution();

            var solutionProject = new VisualStudioSolutionProject {
                TypeGuid = new Guid(VisualStudioSolutionProjectTypeIds.SolutionFolderGuid)
            };

            solutionProject.Solution = solution;
            visualStudioProjectWriter.WriteProject("file", solutionProject);

            mockFileReaderWriter.Received(0).WriteFile(Arg.Any <string>(), Arg.Any <MemoryStream>());
        }
Beispiel #25
0
        private static ISolution LoadSolution(ProjectOption options)
        {
            var currentDir = Directory.GetCurrentDirectory();

            var solutionFile = Path.Combine(currentDir, options.Solution);

            if (System.IO.File.Exists(solutionFile))
            {
                return(VisualStudioSolution.Load(solutionFile));
            }

            throw new Exception("Solution file: " + options.Solution + "could not be found.");
        }
        private VisualStudioSolutionProject ResolveProject(VisualStudioSolution solution, MondopAssembly assembly)
        {
            VisualStudioSolutionProject project = solution.Projects.FirstOrDefault(
                x => x.Name.Equals(assembly.Name));

            if (project != null)
            {
                return(project);
            }

            project = NewProject(solution, assembly.Name, Guid.Parse(VisualStudioSolutionProjectTypeIds.CsProjectGuid), "Library",
                                 assembly.Folder, assembly.Namespace, "4.6.2");

            return(project);
        }
Beispiel #27
0
        public void CanAccessProjectsBeforeSolutionExists()
        {
            // arrange
            var solution = new VisualStudioSolution {
                SolutionPath = Path.Combine(SolutionUnzipDirectory, @"TestSolution\TestSolution.sln")
            };

            // act
            Task <IEnumerable <string> > outputFiles = solution.Projects.Select(p => p.OutputFile);

            UnzipTestSolution();

            // assert
            Assert.That(outputFiles.Value.ToArray(), Is.EquivalentTo(new [] { @"TestSolution\TestSolution\TestSolution\bin\Debug\TestSolution.dll" }));
        }
Beispiel #28
0
        Clean(ProduceRepository repository, string slnPath)
        {
            if (slnPath == null)
            {
                return;
            }

            var sln   = new VisualStudioSolution(slnPath);
            var projs = FindLocalBuildableProjects(repository, sln);

            var targets = projs.Select(p => $"{p.MSBuildTargetName}:Clean");

            using (LogicalOperation.Start("Cleaning .NET artifacts"))
                DotnetMSBuild(repository, sln, targets);
        }
Beispiel #29
0
 FindDependencyProjects(NuGitRepository repository, VisualStudioSolution sln)
 {
     Guard.NotNull(repository, nameof(repository));
     Guard.NotNull(sln, nameof(sln));
     return
         (sln.ProjectReferences
          .Where(p =>
                 p.TypeId == VisualStudioProjectTypeIds.CSharp ||
                 p.TypeId == VisualStudioProjectTypeIds.CSharpNew)
          .Where(p => !IsTestProject(p))
          .Where(p => !string.IsNullOrWhiteSpace(p.Location))
          .Where(p => PathExtensions.IsDescendantOf(p.AbsoluteLocation, repository.Path))
          .OrderBy(p => p.Name)
          .ToList());
 }
Beispiel #30
0
        Dotnet(ProduceRepository repository, string command, VisualStudioSolution sln, params string[] args)
        {
            Guard.NotNull(repository, nameof(repository));
            Guard.Required(command, nameof(command));
            Guard.NotNull(sln, nameof(sln));

            var dotnetArgs = new List <string>()
            {
                command, sln.Path
            };

            dotnetArgs.AddRange(args);

            Dotnet(repository, dotnetArgs.ToArray());
        }
        public static void Generate(CodeGenSettings settings, List <DatabaseTable> tables)
        {
            //generate project files (classes, static assets)
            List <IVisualStudioProject> projects = GenerateClasses(settings, tables);

            //Add projects to the solution
            VisualStudioSolution solution = new VisualStudioSolution {
                Projects = projects
            };

            solution.Render(settings.CodeGenerationDirectory, settings.SolutionNamespace);

            //generate solution assets (Database scripts, thirdparty assemblies)...
            GenerateStaticSolutionAssets(settings);
            GenerateDynamicSolutionAssets(settings, tables);
        }
        public void BuildIfOutdirOptionIsNull()
        {
            // arrange
            var bounceMock = new Mock<IBounce>() { DefaultValue = Moq.DefaultValue.Mock };
            var shellMock = new Mock<IShellCommandExecutor>();
            var solution = new VisualStudioSolution { SolutionPath = new ImmediateValue<string>(@"TestSolution.sln"), OutputDir = null };

            bounceMock.SetupAllProperties();
            bounceMock.SetupGet(_ => _.ShellCommand).Returns(shellMock.Object);

            // act
            solution.Build(bounceMock.Object);

            // assert
            shellMock.Verify(_ => _.ExecuteAndExpectSuccess(It.IsAny<string>(), It.Is<string>(s => s.Satisfy(v => v == "\"TestSolution.sln\""))));
        }
Beispiel #33
0
        public void Startup_Project_Property_is_Remove_From_Sln_When_Startup_Project_is_remove_from_Solution()
        {
            var solution = VisualStudioSolution.Create(@"c:\TestProject\Test.sln", "Test", false);

            solution.SaveEnabled = false;

            var startupProject = new TestProject("c:\\TestProject\\Project1\\Project.csproj");

            solution.AddItem(startupProject);

            solution.StartupProject = startupProject;

            solution.RemoveItem(startupProject);

            Assert.Null(solution.StartupProject);
        }
            public void ShouldAppenedGlobalSectionEntriesForEachProject()
            {
                var builder = new VisualStudioSolution();

                var nestedItems = new List<ProjectItem>();
                var a = Guid.NewGuid();
                var b = Guid.NewGuid();
                var c = Guid.NewGuid();

                nestedItems.Add(new ProjectItem(a, b));
                nestedItems.Add(new ProjectItem(b, c));
                builder.AddGlobalNestedProjects(nestedItems);
                var nestedBuilder = new StringBuilder();
                nestedBuilder.AppendLine("\tGlobalSection(NestedProjects) = preSolution");
                nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[0].Project, nestedItems[0].Parent,
                    Environment.NewLine);
                nestedBuilder.AppendFormat("\t\t{{{0}}} = {{{1}}}{2}", nestedItems[1].Project, nestedItems[1].Parent,
                    Environment.NewLine);
                nestedBuilder.AppendLine("\tEndGlobalSection");
                builder._global.ToString().Contains(nestedBuilder.ToString());
            }
        public void CanAccessProjectsBeforeSolutionExists()
        {
            // arrange
            var solution = new VisualStudioSolution {SolutionPath = Path.Combine(SolutionUnzipDirectory, @"TestSolution\TestSolution.sln")};

            // act
            Task<IEnumerable<string>> outputFiles = solution.Projects.Select(p => p.OutputFile);

            UnzipTestSolution();

            // assert
            Assert.That(outputFiles.Value.ToArray(), Is.EquivalentTo(new [] {@"TestSolution\TestSolution\TestSolution\bin\Debug\TestSolution.dll"}));
        }
 public void BuildsTheSolution()
 {
     var builder = new VisualStudioSolution();
     builder._header = new StringBuilder("A");
     builder._projects = new StringBuilder("B");
     builder._global = new StringBuilder("C");
     var solution = builder.ToString();
     solution.ShouldEqual("ABC");
 }
Beispiel #37
0
 public VisualStudioProject(VisualStudioSolution solution, Task<string> name) {
     Solution = solution;
     Name = name;
 }
Beispiel #38
0
 public SolutionBuilder(VisualStudioSolution solution)
 {
     this.solution = solution;
 }
 public void SetUp()
 {
     visualStudioSolution = new VisualStudioSolution(@"Bricks.Nant\VisualStudio\SampleSolution.txt", "v3.5");
 }