public void AddProject(string slnFile, CsProj project) { var solutionContents = _fileSystem.ReadStringFromFile(slnFile); var replacedContents = new StringBuilder(); var appended = false; var lines = SplitSolution(solutionContents); lines.Each(line => { if (line.Equals("Global") && !appended) { var projectGuid = "{" + project.ProjectGuid + "}"; var projectType = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\")"; replacedContents.AppendLine("{0} = \"{1}\", \"{2}\", \"{3}\"".ToFormat(projectType, project.Name, project.RelativePath, projectGuid)); replacedContents.AppendLine("EndProject"); appended = true; } replacedContents.AppendLine(line); }); _fileSystem.WriteStringToFile(slnFile, replacedContents.ToString()); }
public CsProj CreateProj(string directory, string projFile) { var proj = new CsProj { RelativePath = FindRelativePath(directory, projFile) }; VisitProj(projFile, proj); return proj; }
public void should_set_project_attributes() { var projectFile = FileSystem.Combine("Templating", "data", "example1", "example1.csproj"); var project = new CsProj(); _projGatherer.VisitProj(projectFile, project); project.ProjectGuid.ShouldEqual("GUID1"); project.Name.ShouldEqual("FUBUPROJECTNAME"); }
public CsProj CreateProj(string directory, string projFile) { var proj = new CsProj { RelativePath = FindRelativePath(directory, projFile) }; VisitProj(projFile, proj); return(proj); }
public void VisitProj(string projFile, CsProj project) { var doc = XDocument.Load(projFile, LoadOptions.None); var root = doc .Elements() .First(e => e.Name.LocalName == "Project") .Elements() .First(e => e.Name.LocalName == "PropertyGroup"); project.ProjectGuid = root .Elements() .First(e => e.Name.LocalName == "ProjectGuid") .Value .TrimStart('{') .TrimEnd('}'); project.Name = root .Elements() .First(e => e.Name.LocalName == "AssemblyName") .Value; }
public void should_add_project_references() { // build it up through a stringbuilder to use the environment-specific newline var solutionBuilder = new StringBuilder("Microsoft Visual Studio Solution File, Format Version 11.00") .AppendLine() .AppendLine("# Visual Studio 2010") .AppendLine(@"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""FubuMVC.StructureMap"", ""FubuMVC.StructureMap\FubuMVC.StructureMap.csproj"", ""{ABFEA520-820C-4B77-9015-6A09E24252FA}""") .AppendLine("EndProject") .AppendLine("Global") .AppendLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution") .AppendLine(" Debug|Any CPU = Debug|Any CPU") .AppendLine(" Release|Any CPU = Release|Any CPU") .AppendLine(" EndGlobalSection") .AppendLine(" GlobalSection(SolutionProperties) = preSolution") .AppendLine(" HideSolutionNode = FALSE") .AppendLine(" EndGlobalSection") .AppendLine("EndGlobal"); var system = new FileSystem(); var solutionFile = "tmp.sln"; system.AppendStringToFile(solutionFile, solutionBuilder.ToString()); var project = new CsProj { Name = "Test", ProjectGuid = "123", RelativePath = @"example1\example1.csproj" }; var service = new SolutionFileService(system); service.AddProject(solutionFile, project); var solutionContents = system.ReadStringFromFile(solutionFile); var lines = service.SplitSolution(solutionContents); lines[4].ShouldEqual("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Test\", \"example1\\example1.csproj\", \"{123}\""); lines[5].ShouldEqual("EndProject"); system.DeleteFile(solutionFile); }
public void AddProject(CsProj project) { _projects.Fill(project); }