From 743e0ab636fff6c052a8712c711121e73a08c9bc Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Tue, 11 Mar 2014 14:59:56 -0600 Subject: [PATCH] Replaced calls to obsolete create project methods with the ProjectCreator #84 --- src/FubuCsProjFile.Testing/ContentTester.cs | 9 ++-- .../CsProjFileTester.cs | 26 +++++------ src/FubuCsProjFile.Testing/NoneTester.cs | 5 ++- .../Templating/AssemblyReferenceTester.cs | 21 ++++----- .../Templating/CodeFileTemplateTester.cs | 7 ++- .../Templating/CodeFileTester.cs | 3 +- .../Templating/CopyProjectReferencesTester.cs | 11 ++--- .../Templating/ProjectDirectoryTester.cs | 12 ++--- .../ProjectFiles/CsProj/CsProjFile.cs | 44 +++++-------------- .../ProjectFiles/IProjectFile.cs | 28 +++++++++++- src/FubuCsProjFile/Solution.cs | 20 +++++++-- src/FubuCsProjFile/SolutionProject.cs | 37 +++++++++------- .../Runtime/AssemblyInfoAlteration.cs | 3 +- .../Templating/Runtime/CodeFileTemplate.cs | 3 +- .../Templating/Runtime/CopyFileToProject.cs | 4 +- .../Runtime/CopyProjectReferences.cs | 14 +++--- .../Templating/Runtime/IProjectAlteration.cs | 4 +- .../Templating/Runtime/ProjectDirectory.cs | 4 +- .../Templating/Runtime/SystemReference.cs | 4 +- 19 files changed, 138 insertions(+), 121 deletions(-) diff --git a/src/FubuCsProjFile.Testing/ContentTester.cs b/src/FubuCsProjFile.Testing/ContentTester.cs index 303f9bf..9280cf0 100644 --- a/src/FubuCsProjFile.Testing/ContentTester.cs +++ b/src/FubuCsProjFile.Testing/ContentTester.cs @@ -1,4 +1,5 @@ -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; +using FubuCsProjFile.ProjectFiles.CsProj; using FubuTestingSupport; using NUnit.Framework; @@ -17,7 +18,7 @@ public void default_copy_to_behavior_is_never() [Test] public void can_add_and_load_never_copy_content() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = ProjectCreator.CreateAtSolutionDirectory("MyProj", "myproj", ProjectType.CsProj); var content = new Content("Something.txt") { CopyToOutputDirectory = ContentCopy.Never @@ -35,7 +36,7 @@ public void can_add_and_load_never_copy_content() [Test] public void can_add_and_load_always_copy_content() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = ProjectCreator.CreateAtSolutionDirectory("MyProj", "myproj", ProjectType.CsProj); var content = new Content("Something.txt") { CopyToOutputDirectory = ContentCopy.Always @@ -55,7 +56,7 @@ public void can_add_and_load_always_copy_content() public void can_add_and_load_IfNewer_copy_content() { // SAMPLE: adding-content-to-csprojfile - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = ProjectCreator.CreateAtSolutionDirectory("MyProj", "myproj", ProjectType.CsProj); var content = new Content("Something.txt") { CopyToOutputDirectory = ContentCopy.IfNewer diff --git a/src/FubuCsProjFile.Testing/CsProjFileTester.cs b/src/FubuCsProjFile.Testing/CsProjFileTester.cs index 2797fab..57390f9 100644 --- a/src/FubuCsProjFile.Testing/CsProjFileTester.cs +++ b/src/FubuCsProjFile.Testing/CsProjFileTester.cs @@ -1,6 +1,4 @@ using System; -using System.Diagnostics; -using System.IO; using FubuCore; using FubuCsProjFile.MSBuild; using FubuCsProjFile.ProjectFiles.CsProj; @@ -35,7 +33,7 @@ public void SetUp() [Test] public void creating_a_new_csprojfile_relative_to_a_solution_directory_creates_a_guid() { - var project = CsProjFile.CreateAtSolutionDirectory("Foo", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("Foo", "myproj"); project.ProjectGuid.ShouldNotEqual(Guid.Empty); } @@ -43,7 +41,7 @@ public void creating_a_new_csprojfile_relative_to_a_solution_directory_creates_a [Test] public void creating_a_new_csprojectfile_create_a_guid() { - var project = CsProjFile.CreateAtLocation("Foo.AssemblyName.csproj", "Foo.AssemblyName"); + var project = new CsProjCreator().CreateAtLocation("Foo.AssemblyName.csproj", "Foo.AssemblyName"); project.ProjectGuid.ShouldNotEqual(Guid.Empty); } @@ -70,7 +68,7 @@ public void write_and_then_read_the_dot_net_version_from_csprojfile() [Test] public void creating_a_new_csprojfile_class_library_is_default() { - var project = CsProjFile.CreateAtSolutionDirectory("Foo", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("Foo", "myproj"); project.ProjectTypes().Single().ShouldEqual(Guid.Parse("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC")); } @@ -92,7 +90,7 @@ public void read_the_project_name() [Test] public void sets_the_assembly_name_and_root_namespace_on_creation() { - var project = CsProjFile.CreateAtSolutionDirectory("Goofy", "Directory"); + var project = new CsProjCreator().CreateAtSolutionDirectory("Goofy", "Directory"); project.RootNamespace.ShouldEqual("Goofy"); project.AssemblyName.ShouldEqual("Goofy"); @@ -116,7 +114,7 @@ public void read_project_type_as_a_class_library_if_no_explicit_project_type() [Test] public void remove_code_file() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("foo.cs"); project.Add("bar.cs"); @@ -140,7 +138,7 @@ public void remove_code_file() [Test] public void remove_code_file_2() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("foo.cs"); project.Add("bar.cs"); @@ -168,7 +166,7 @@ public void add_code_files() fileSystem.WriteStringToFile("myproj".AppendPath("foo.cs"), "using System.Web;"); fileSystem.WriteStringToFile("myproj".AppendPath("bar.cs"), "using System.Web;"); - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("foo.cs"); project.Add("bar.cs"); @@ -196,7 +194,7 @@ public void adding_items_is_idempotent() fileSystem.WriteStringToFile("myproj".AppendPath("foo.cs"), "using System.Web;"); fileSystem.WriteStringToFile("myproj".AppendPath("bar.cs"), "using System.Web;"); - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("foo.cs"); project.Add("bar.cs"); @@ -235,7 +233,7 @@ public void can_write_embedded_resources() fileSystem.WriteStringToFile("myproj".AppendPath("foo.txt"), "using System.Web;"); fileSystem.WriteStringToFile("myproj".AppendPath("bar.txt"), "using System.Web;"); - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("foo.txt"); project.Add("bar.txt"); @@ -427,7 +425,7 @@ public void can_read_then_change_and_save_a_projecet_reference_item() [Test] public void can_write_system_assemblies() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add("System.Configuration"); project.Add("System.Security"); @@ -444,7 +442,7 @@ public void can_write_system_assemblies() public void can_write_assembly_reference_with_hint_path() { var hintPath = @"..\packages\RhinoMocks\lib\net\Rhino.Mocks.dll"; - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); project.Add(new AssemblyReference("Rhino.Mocks", hintPath)); project.Save(); @@ -464,7 +462,7 @@ public void can_write_and_read_project_references() var include = @"..\OtherProject\OtherProject.csproj"; - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = new CsProjCreator().CreateAtSolutionDirectory("MyProj", "myproj"); var reference1 = new ProjectReference(include) { ProjectName = "OtherProject", diff --git a/src/FubuCsProjFile.Testing/NoneTester.cs b/src/FubuCsProjFile.Testing/NoneTester.cs index 4eb7856..8b22e50 100644 --- a/src/FubuCsProjFile.Testing/NoneTester.cs +++ b/src/FubuCsProjFile.Testing/NoneTester.cs @@ -1,4 +1,5 @@ -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; +using FubuCsProjFile.ProjectFiles.CsProj; using FubuTestingSupport; using NUnit.Framework; @@ -10,7 +11,7 @@ public class NoneTester [Test] public void can_add_a_file_with_build_action_none() { - var project = CsProjFile.CreateAtSolutionDirectory("MyProj", "myproj"); + var project = ProjectCreator.CreateAtSolutionDirectory("MyProj", "myproj", ProjectType.CsProj); var content = new None("packages.config"); project.Add(content); diff --git a/src/FubuCsProjFile.Testing/Templating/AssemblyReferenceTester.cs b/src/FubuCsProjFile.Testing/Templating/AssemblyReferenceTester.cs index a1c5bd6..add33e3 100644 --- a/src/FubuCsProjFile.Testing/Templating/AssemblyReferenceTester.cs +++ b/src/FubuCsProjFile.Testing/Templating/AssemblyReferenceTester.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; using FubuCsProjFile.Templating.Planning; using FubuCsProjFile.Templating.Runtime; @@ -36,7 +37,7 @@ public void can_write_assembly_reference_to_a_project() public void adding_an_assembly_reference() { // SAMPLE: assembly-reference - var project = CsProjFile.CreateAtLocation("MyProject.csproj", "MyProject"); + var project = ProjectCreator.CreateAtLocation("MyProject.csproj", "MyProject", ProjectType.CsProj); project.Add(new AssemblyReference("MyOtherLibrary") { HintPath = "../packages/MyOtherLibrary/lib/MyOtherLibrary.dll", @@ -66,7 +67,7 @@ public void adding_an_assembly_reference() [Test] public void can_write_and_read_fusion_name() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { FusionName = "some fusion" @@ -85,7 +86,7 @@ public void can_write_and_read_fusion_name() [Test] public void can_write_and_read_Aliases() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { Aliases = "some alias" @@ -104,7 +105,7 @@ public void can_write_and_read_Aliases() [Test] public void can_write_and_read_display_name() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { DisplayName = "some name" @@ -123,7 +124,7 @@ public void can_write_and_read_display_name() [Test] public void can_write_and_read_SpecificVersion_true() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { SpecificVersion = true @@ -142,7 +143,7 @@ public void can_write_and_read_SpecificVersion_true() [Test] public void can_write_and_read_SpecificVersion_false() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { SpecificVersion = false @@ -161,7 +162,7 @@ public void can_write_and_read_SpecificVersion_false() [Test] public void can_write_and_read_SpecificVersion_null() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { SpecificVersion = null @@ -181,7 +182,7 @@ public void can_write_and_read_SpecificVersion_null() [Test] public void can_write_and_read_Private_true() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { Private = true @@ -200,7 +201,7 @@ public void can_write_and_read_Private_true() [Test] public void can_write_and_read_Private_false() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { Private = false @@ -219,7 +220,7 @@ public void can_write_and_read_Private_false() [Test] public void can_write_and_read_Private_null() { - var project = CsProjFile.CreateAtLocation("Foo.csproj", "Foo"); + var project = ProjectCreator.CreateAtLocation("Foo.csproj", "Foo", ProjectType.CsProj); var assemblyReference = new AssemblyReference("Foo") { Private = null diff --git a/src/FubuCsProjFile.Testing/Templating/CodeFileTemplateTester.cs b/src/FubuCsProjFile.Testing/Templating/CodeFileTemplateTester.cs index 2340ab2..66d1b42 100644 --- a/src/FubuCsProjFile.Testing/Templating/CodeFileTemplateTester.cs +++ b/src/FubuCsProjFile.Testing/Templating/CodeFileTemplateTester.cs @@ -1,7 +1,6 @@ using System.IO; using FubuCore; -using FubuCsProjFile.ProjectFiles.CsProj; -using FubuCsProjFile.Templating; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.Templating.Runtime; using NUnit.Framework; using FubuTestingSupport; @@ -12,7 +11,7 @@ namespace FubuCsProjFile.Testing.Templating [TestFixture] public class CodeFileTemplateTester { - private CsProjFile theProject; + private IProjectFile theProject; private ProjectPlan thePlan; [TestFixtureSetUp] @@ -21,7 +20,7 @@ public void SetUp() new FileSystem().DeleteDirectory("Templated"); new FileSystem().CreateDirectory("Templated"); - theProject = CsProjFile.CreateAtSolutionDirectory("TemplatedProject", "Templated"); + theProject = ProjectCreator.CreateAtSolutionDirectory("TemplatedProject", "Templated", ProjectType.CsProj); thePlan = new ProjectPlan(theProject.ProjectName); } diff --git a/src/FubuCsProjFile.Testing/Templating/CodeFileTester.cs b/src/FubuCsProjFile.Testing/Templating/CodeFileTester.cs index db8b8a4..547b8ec 100644 --- a/src/FubuCsProjFile.Testing/Templating/CodeFileTester.cs +++ b/src/FubuCsProjFile.Testing/Templating/CodeFileTester.cs @@ -1,4 +1,5 @@ using System; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; using NUnit.Framework; using FubuTestingSupport; @@ -12,7 +13,7 @@ public class CodeFileTester [Test] public void read_and_write_with_a_link() { - var project = CsProjFile.CreateAtSolutionDirectory("Foo", Guid.NewGuid().ToString()); + var project = ProjectCreator.CreateAtSolutionDirectory("Foo", Guid.NewGuid().ToString(), ProjectType.CsProj); var file = new CodeFile("..\\CommonAssemblyInfo.cs") {Link = "CommonAssemblyInfo.cs"}; diff --git a/src/FubuCsProjFile.Testing/Templating/CopyProjectReferencesTester.cs b/src/FubuCsProjFile.Testing/Templating/CopyProjectReferencesTester.cs index b138291..61a2ec8 100644 --- a/src/FubuCsProjFile.Testing/Templating/CopyProjectReferencesTester.cs +++ b/src/FubuCsProjFile.Testing/Templating/CopyProjectReferencesTester.cs @@ -1,14 +1,11 @@ -using System.Diagnostics; -using System.IO; -using FubuCsProjFile.ProjectFiles.CsProj; -using FubuCsProjFile.Templating; +using System.IO; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.Templating.Planning; using FubuCsProjFile.Templating.Runtime; using NUnit.Framework; using FubuCore; using FubuTestingSupport; using System.Linq; -using System.Collections.Generic; namespace FubuCsProjFile.Testing.Templating { @@ -16,8 +13,8 @@ namespace FubuCsProjFile.Testing.Templating public class CopyProjectReferencesTester { private TemplatePlan thePlan; - private CsProjFile theOriginalProject; - private CsProjFile theTestingProject; + private IProjectFile theOriginalProject; + private IProjectFile theTestingProject; private ProjectPlan testingPlan; [SetUp] diff --git a/src/FubuCsProjFile.Testing/Templating/ProjectDirectoryTester.cs b/src/FubuCsProjFile.Testing/Templating/ProjectDirectoryTester.cs index 8a28e05..93f9e6d 100644 --- a/src/FubuCsProjFile.Testing/Templating/ProjectDirectoryTester.cs +++ b/src/FubuCsProjFile.Testing/Templating/ProjectDirectoryTester.cs @@ -1,8 +1,6 @@ -using System.IO; -using System.Linq; +using System.Linq; using FubuCore; -using FubuCsProjFile.ProjectFiles.CsProj; -using FubuCsProjFile.Templating; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.Templating.Graph; using FubuCsProjFile.Templating.Runtime; using FubuTestingSupport; @@ -13,7 +11,7 @@ namespace FubuCsProjFile.Testing.Templating [TestFixture] public class ProjectDirectoryTester { - private CsProjFile csProjFile; + private IProjectFile csProjFile; [SetUp] public void SetUp() @@ -21,9 +19,7 @@ public void SetUp() TemplateLibrary.FileSystem.DeleteDirectory("temp-solution"); TemplateLibrary.FileSystem.CreateDirectory("temp-solution"); - csProjFile = CsProjFile.CreateAtSolutionDirectory("MyProj", "temp-solution"); - - + csProjFile = ProjectCreator.CreateAtSolutionDirectory("MyProj", "temp-solution", ProjectType.CsProj); } [Test] diff --git a/src/FubuCsProjFile/ProjectFiles/CsProj/CsProjFile.cs b/src/FubuCsProjFile/ProjectFiles/CsProj/CsProjFile.cs index 796b1cf..d4eab7c 100644 --- a/src/FubuCsProjFile/ProjectFiles/CsProj/CsProjFile.cs +++ b/src/FubuCsProjFile/ProjectFiles/CsProj/CsProjFile.cs @@ -14,7 +14,7 @@ public static class DotNetVersion public static readonly string V45 = "v4.5"; } - public class CsProjFile : IProjectFile + public class CsProjFile : IInternalProjectFile { /* MyProject @@ -50,13 +50,6 @@ public Guid ProjectGuid return raw.IsEmpty() ? Guid.Empty : Guid.Parse(raw.TrimStart('{').TrimEnd('}')); } - internal set - { - var group = _project.PropertyGroups.FirstOrDefault(x => x.Properties.Any(p => p.Name == PROJECT_GUID)) - ?? _project.PropertyGroups.FirstOrDefault() ?? _project.AddNewPropertyGroup(true); - - group.SetPropertyValue(PROJECT_GUID, value.ToString().ToUpper(), true); - } } public string AssemblyName @@ -134,18 +127,6 @@ public void Add(T item) where T : ProjectItem }); } - /// - /// Creates a new CsProjFile in a folder relative to the solution folder - /// - /// - /// - /// - [Obsolete("Use FubuCsProj.ProjectFiles.ProjectCreator.CreateAtSolutionDirectory instead")] - public static CsProjFile CreateAtSolutionDirectory(string assemblyName, string directory) - { - return ProjectCreator.CreateAtSolutionDirectory(assemblyName, directory, ProjectType.CsProj) as CsProjFile; - } - /// /// Load an existing CsProjFile from the filename given /// @@ -157,19 +138,6 @@ public static CsProjFile LoadFrom(string filename) return new CsProjFile(filename, project); } - /// - /// Creates a new class library project at the given filename - /// and assembly name - /// - /// - /// - /// - [Obsolete("Use FubuCsProj.ProjectFiles.ProjectCreator.CreateAtLocation instead")] - public static CsProjFile CreateAtLocation(string filename, string assemblyName) - { - return ProjectCreator.CreateAtLocation(filename, assemblyName, ProjectType.CsProj) as CsProjFile; - } - public string ProjectName { get { return Path.GetFileNameWithoutExtension(_fileName); } @@ -285,7 +253,7 @@ public string PathTo(CodeFile codeFile) } } - public void Remove(T item) where T : ProjectItem, new() + public void Remove(T item) where T : ProjectItem { _projectItemCache.Remove(item.Include); @@ -295,6 +263,14 @@ public string PathTo(CodeFile codeFile) element.Remove(); } } + + void IInternalProjectFile.SetProjectGuid(Guid newGuid) + { + var group = _project.PropertyGroups.FirstOrDefault(x => x.Properties.Any(p => p.Name == PROJECT_GUID)) + ?? _project.PropertyGroups.FirstOrDefault() ?? _project.AddNewPropertyGroup(true); + + group.SetPropertyValue(PROJECT_GUID, newGuid.ToString().ToUpper(), true); + } } } diff --git a/src/FubuCsProjFile/ProjectFiles/IProjectFile.cs b/src/FubuCsProjFile/ProjectFiles/IProjectFile.cs index 9687615..72fd6fe 100644 --- a/src/FubuCsProjFile/ProjectFiles/IProjectFile.cs +++ b/src/FubuCsProjFile/ProjectFiles/IProjectFile.cs @@ -1,7 +1,31 @@ -namespace FubuCsProjFile.ProjectFiles +using System; +using System.Collections.Generic; + +namespace FubuCsProjFile.ProjectFiles { public interface IProjectFile { - + string ProjectName { get; } + string FileName { get; } + Guid ProjectGuid { get; } + string AssemblyName { get; set; } + string RootNamespace { get; set; } + string DotNetVersion { get; set; } + string ProjectDirectory { get; } + SourceControlInformation SourceControlInformation { get; set; } + IEnumerable ProjectTypes(); + void Save(); + T Find(string arg) where T : ProjectItem, new(); + T Add(string arg) where T : ProjectItem, new(); + void Add(T arg) where T : ProjectItem; + string PathTo(CodeFile arg); + IEnumerable All() where T : ProjectItem, new(); + void Remove(string arg) where T : ProjectItem, new(); + void Remove(T arg) where T : ProjectItem; + } + + internal interface IInternalProjectFile : IProjectFile + { + void SetProjectGuid(Guid projectGuid); } } \ No newline at end of file diff --git a/src/FubuCsProjFile/Solution.cs b/src/FubuCsProjFile/Solution.cs index f86035b..f56afa7 100644 --- a/src/FubuCsProjFile/Solution.cs +++ b/src/FubuCsProjFile/Solution.cs @@ -6,6 +6,7 @@ using System.Linq; using FubuCore.Util; using FubuCsProjFile.MSBuild; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; namespace FubuCsProjFile @@ -261,7 +262,20 @@ public IEnumerable Projects /// /// /// - public SolutionProject AddProject( string projectName) + public SolutionProject AddProject(string projectName) + { + return AddProject(projectName, ProjectType.CsProj); + } + + /// + /// Attaches an existing project of this name to the solution or + /// creates a new project based on a Class Library and attaches + /// to the solution + /// + /// + /// + /// + public SolutionProject AddProject(string projectName, ProjectType type) { var existing = FindProject(projectName); if (existing != null) @@ -269,7 +283,7 @@ public SolutionProject AddProject( string projectName) return existing; } - var reference = SolutionProject.CreateNewAt(ParentDirectory, projectName); + var reference = SolutionProject.CreateNewAt(ParentDirectory, projectName, type); _projects.Add(reference); return reference; @@ -309,7 +323,7 @@ public SolutionProject AddProjectFromTemplate(string projectName, string templat var project = MSBuildProject.CreateFromFile(projectName, templateFile); var csProjFile = new CsProjFile(ParentDirectory.AppendPath(projectName, projectName + ".csproj"), project); - csProjFile.ProjectGuid = Guid.NewGuid(); + csProjFile.As().SetProjectGuid(Guid.NewGuid()); var reference = new SolutionProject(csProjFile, ParentDirectory); _projects.Add(reference); diff --git a/src/FubuCsProjFile/SolutionProject.cs b/src/FubuCsProjFile/SolutionProject.cs index 82a590f..87d35c2 100644 --- a/src/FubuCsProjFile/SolutionProject.cs +++ b/src/FubuCsProjFile/SolutionProject.cs @@ -4,19 +4,19 @@ using FubuCore; using System.Linq; using FubuCsProjFile.MSBuild; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; namespace FubuCsProjFile { public class SolutionProject { - public static SolutionProject CreateNewAt(string solutionDirectory, string projectName) + public static SolutionProject CreateNewAt(string solutionDirectory, string projectName, ProjectType type) { - var csProjFile = CsProjFile.CreateAtSolutionDirectory(projectName, solutionDirectory); + var csProjFile = ProjectCreator.CreateAtSolutionDirectory(projectName, solutionDirectory, type); return new SolutionProject(csProjFile, solutionDirectory); } - public static readonly string ProjectLineTemplate = "Project(\"{{{0}}}\") = \"{1}\", \"{2}\", \"{{{3}}}\""; private readonly Guid _projectType; private readonly Guid _projectGuid; @@ -24,18 +24,23 @@ public static SolutionProject CreateNewAt(string solutionDirectory, string proje private readonly string _relativePath; private readonly IList _directives = new List(); - private readonly Lazy _project; + private readonly Lazy _project; + + public SolutionProject(IProjectFile projectFile, string solutionDirectory) + { + _project = new Lazy(() => projectFile); + _projectName = projectFile.ProjectName; + _relativePath = projectFile.FileName.PathRelativeTo(solutionDirectory); + _projectType = projectFile.ProjectTypes().LastOrDefault(); + _projectGuid = projectFile.ProjectGuid; + } - public SolutionProject(CsProjFile csProjFile, string solutionDirectory) + public SolutionProject(string text, string solutionDirectory) : this(text, solutionDirectory, ProjectFiles.ProjectType.CsProj) { - _project = new Lazy(() => csProjFile); - _projectName = csProjFile.ProjectName; - _relativePath = csProjFile.FileName.PathRelativeTo(solutionDirectory); - _projectType = csProjFile.ProjectTypes().LastOrDefault(); - _projectGuid = csProjFile.ProjectGuid; + } - public SolutionProject(string text, string solutionDirectory) + public SolutionProject(string text, string solutionDirectory, ProjectType type) { var parts = text.ToDelimitedArray('='); _projectType = Guid.Parse(parts.First().TextBetweenSquiggles()); @@ -46,7 +51,7 @@ public SolutionProject(string text, string solutionDirectory) _relativePath = secondParts.ElementAt(1).TextBetweenQuotes().Replace("\\", "/"); // Windows is forgiving - _project = new Lazy(() => { + _project = new Lazy(() => { var filename = solutionDirectory.AppendPath(_relativePath); if (File.Exists(filename)) @@ -56,8 +61,8 @@ public SolutionProject(string text, string solutionDirectory) return projFile; } - var project = CsProjFile.CreateAtLocation(filename, _projectName); - project.ProjectGuid = _projectGuid; + var project = ProjectCreator.CreateAtLocation(filename, _projectName, type); + project.As().SetProjectGuid(_projectGuid); return project; }); @@ -116,7 +121,7 @@ public string RelativePath get { return _relativePath; } } - public CsProjFile Project + public IProjectFile Project { get { return _project.Value; } } @@ -146,4 +151,4 @@ public static string TextBetweenQuotes(this string text) return text.Trim().TrimStart('"').TrimEnd('"'); } } -} \ No newline at end of file +} diff --git a/src/FubuCsProjFile/Templating/Runtime/AssemblyInfoAlteration.cs b/src/FubuCsProjFile/Templating/Runtime/AssemblyInfoAlteration.cs index 0bad102..7d8b6f2 100644 --- a/src/FubuCsProjFile/Templating/Runtime/AssemblyInfoAlteration.cs +++ b/src/FubuCsProjFile/Templating/Runtime/AssemblyInfoAlteration.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using FubuCore; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; namespace FubuCsProjFile.Templating.Runtime @@ -17,7 +18,7 @@ public AssemblyInfoAlteration(params string[] additions) _additions = additions; } - public void Alter(CsProjFile file, ProjectPlan plan) + public void Alter(IProjectFile file, ProjectPlan plan) { var assemblyInfoPath = Path.Combine (AssemblyInfoPath); var codeFile = file.Find(assemblyInfoPath) ?? file.Add(assemblyInfoPath); diff --git a/src/FubuCsProjFile/Templating/Runtime/CodeFileTemplate.cs b/src/FubuCsProjFile/Templating/Runtime/CodeFileTemplate.cs index cd08487..96b363d 100644 --- a/src/FubuCsProjFile/Templating/Runtime/CodeFileTemplate.cs +++ b/src/FubuCsProjFile/Templating/Runtime/CodeFileTemplate.cs @@ -2,6 +2,7 @@ using System.IO; using System.Reflection; using FubuCore; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.ProjectFiles.CsProj; namespace FubuCsProjFile.Templating.Runtime @@ -54,7 +55,7 @@ public string RawText - public void Alter(CsProjFile file, ProjectPlan plan) + public void Alter(IProjectFile file, ProjectPlan plan) { var includePath = plan.ApplySubstitutions(_relativePath); var filename = file.FileName.ParentDirectory().AppendPath(includePath); diff --git a/src/FubuCsProjFile/Templating/Runtime/CopyFileToProject.cs b/src/FubuCsProjFile/Templating/Runtime/CopyFileToProject.cs index 6fd9278..f915f14 100644 --- a/src/FubuCsProjFile/Templating/Runtime/CopyFileToProject.cs +++ b/src/FubuCsProjFile/Templating/Runtime/CopyFileToProject.cs @@ -1,5 +1,5 @@ using FubuCore; -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; namespace FubuCsProjFile.Templating.Runtime { @@ -14,7 +14,7 @@ public CopyFileToProject(string relativePath, string source) _source = source; } - public void Alter(CsProjFile file, ProjectPlan plan) + public void Alter(IProjectFile file, ProjectPlan plan) { var fileSystem = new FileSystem(); var rawText = fileSystem.ReadStringFromFile(_source); diff --git a/src/FubuCsProjFile/Templating/Runtime/CopyProjectReferences.cs b/src/FubuCsProjFile/Templating/Runtime/CopyProjectReferences.cs index 978c724..3594394 100644 --- a/src/FubuCsProjFile/Templating/Runtime/CopyProjectReferences.cs +++ b/src/FubuCsProjFile/Templating/Runtime/CopyProjectReferences.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; using FubuCore; -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.Templating.Planning; namespace FubuCsProjFile.Templating.Runtime @@ -36,13 +36,15 @@ public void Alter(TemplatePlan plan) buildProjectReference(original, testProject); } - private static void copyNugetDeclarations(ProjectPlan originalPlan, ProjectPlan testPlan, CsProjFile original, - CsProjFile testProject) + private static void copyNugetDeclarations(ProjectPlan originalPlan, + ProjectPlan testPlan, + IProjectFile original, + IProjectFile testProject) { originalPlan.NugetDeclarations.Each(x => testPlan.NugetDeclarations.Fill(x)); original.All() - .Where(x => x.HintPath.IsEmpty()) - .Each(x => testProject.Add(x.Include)); + .Where(x => x.HintPath.IsEmpty()) + .Each(x => testProject.Add(x.Include)); } private void findNugetsInOriginalRippleDeclarations(TemplatePlan plan, ProjectPlan testPlan) @@ -51,7 +53,7 @@ private void findNugetsInOriginalRippleDeclarations(TemplatePlan plan, ProjectPl plan.FileSystem.ReadTextFile(configFile, line => { if (line.IsNotEmpty()) testPlan.NugetDeclarations.Fill(line); }); } - private static void buildProjectReference(CsProjFile original, CsProjFile testProject) + private static void buildProjectReference(IProjectFile original, IProjectFile testProject) { var relativePathToTheOriginal = original.FileName.PathRelativeTo(testProject.FileName); if (original.FileName.ParentDirectory().ParentDirectory() == diff --git a/src/FubuCsProjFile/Templating/Runtime/IProjectAlteration.cs b/src/FubuCsProjFile/Templating/Runtime/IProjectAlteration.cs index 74448c9..d3aac0a 100644 --- a/src/FubuCsProjFile/Templating/Runtime/IProjectAlteration.cs +++ b/src/FubuCsProjFile/Templating/Runtime/IProjectAlteration.cs @@ -1,9 +1,9 @@ -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; namespace FubuCsProjFile.Templating.Runtime { public interface IProjectAlteration { - void Alter(CsProjFile file, ProjectPlan plan); + void Alter(IProjectFile file, ProjectPlan plan); } } \ No newline at end of file diff --git a/src/FubuCsProjFile/Templating/Runtime/ProjectDirectory.cs b/src/FubuCsProjFile/Templating/Runtime/ProjectDirectory.cs index 44f2d0d..7bd1320 100644 --- a/src/FubuCsProjFile/Templating/Runtime/ProjectDirectory.cs +++ b/src/FubuCsProjFile/Templating/Runtime/ProjectDirectory.cs @@ -2,7 +2,7 @@ using System.IO; using System.Linq; using FubuCore; -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; using FubuCsProjFile.Templating.Graph; namespace FubuCsProjFile.Templating.Runtime @@ -21,7 +21,7 @@ public string RelativePath get { return _relativePath; } } - public void Alter(CsProjFile file, ProjectPlan plan) + public void Alter(IProjectFile file, ProjectPlan plan) { TemplateLibrary.FileSystem.CreateDirectory(file.ProjectDirectory.AppendPath(_relativePath)); } diff --git a/src/FubuCsProjFile/Templating/Runtime/SystemReference.cs b/src/FubuCsProjFile/Templating/Runtime/SystemReference.cs index eae071b..2828262 100644 --- a/src/FubuCsProjFile/Templating/Runtime/SystemReference.cs +++ b/src/FubuCsProjFile/Templating/Runtime/SystemReference.cs @@ -1,5 +1,5 @@ using System; -using FubuCsProjFile.ProjectFiles.CsProj; +using FubuCsProjFile.ProjectFiles; namespace FubuCsProjFile.Templating.Runtime { @@ -13,7 +13,7 @@ public SystemReference(string assemblyName) _assemblyName = assemblyName; } - public void Alter(CsProjFile file, ProjectPlan plan) + public void Alter(IProjectFile file, ProjectPlan plan) { file.Add(_assemblyName); }