Permalink
Browse files

Added support for VS 2008, alternate solution file output path, addit…

…ional search paths for projects outside of projects root.
  • Loading branch information...
1 parent c214a94 commit 132ee2e107061886c8e879eae16a16e67f242b77 @AaronTorgerson committed Mar 26, 2011
View
11 README
@@ -1,15 +1,18 @@
SlimJim is a Visual Studio solution file generator.
Current features:
-* Create solution files for VS 2010.
+* Create solution files for VS 2010 and 2008.
* Create solution file for one or more target projects in a file tree beneath a specfic root directory. Solution will contain:
** All projects that reference one or more of the target projects either by assembly or project reference and recursively each project refereced by those projects by project reference.
** All projects that the target projects reference by project reference and recursively each project refereced by those projects by project reference.
* Create solution file for working directory or specified projects root directory with either a specified or default name.
+* Specify folder to contain generated solution files instead of projects root.
+* Specifiy addition search paths outside of your project root to search for additional projects.
Upcoming features:
* .slim file in your projects root directory can contain details for generation of one or more solution files. This will allow for simple invocation, e.g. "C:\MyProjects>slimjim".
-* Support for VS 2008
-* Specify folder to contain generated solution files instead of projects root.
* Generate solution file for entire project graph.
-* Specifiy addition search paths outside of your project root to search for additional projects.
+
+Known issues:
+* If SlnOutputPath does not exist, an exception is raised.
+* All paths must be absolute. Relative paths for additional search paths, projects root, and solution output path will be supported soon.
@@ -1,7 +1,3 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
using NUnit.Framework;
using SlimJim.Infrastructure;
using SlimJim.Model;
@@ -79,25 +75,25 @@ public void SpecifiedSlnOuputPath()
[Test]
public void SpecifiedVisualStudioVersion90()
{
- options = ArgsOptionsBuilder.BuildOptions(new[] {@"/v:90"}, WorkingDirectory);
+ options = ArgsOptionsBuilder.BuildOptions(new[] {@"/v:VS2008"}, WorkingDirectory);
- Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion._90));
+ Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion.VS2008));
}
[Test]
public void SpecifiedVisualStudioVersion10()
{
- options = ArgsOptionsBuilder.BuildOptions(new[] { @"/v:100" }, WorkingDirectory);
+ options = ArgsOptionsBuilder.BuildOptions(new[] { @"/v:VS2010" }, WorkingDirectory);
- Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion._100));
+ Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion.VS2010));
}
[Test]
public void InvalidVisualStudioVersionNumber()
{
options = ArgsOptionsBuilder.BuildOptions(new[] {@"/v:dumb"}, WorkingDirectory);
- Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion._90));
+ Assert.That(options.VisualStudioVersion, Is.EqualTo(VisualStudioVersion.VS2010));
}
[Test]
@@ -144,14 +140,6 @@ public void UnspecifiedSolutionNameWithNoTargetProjectsUsesFolderName()
}
[Test]
- public void NoSolutionNameNoTargetProjectsNoWorkingDirUsesDefaultName()
- {
- options = new SlnGenerationOptions();
-
- Assert.That(options.SolutionName, Is.EqualTo("SlimJim"));
- }
-
- [Test]
public void TPrefixAlsoSetsTargetProject()
{
options = ArgsOptionsBuilder.BuildOptions(new[] { @"/t:MyProject" }, WorkingDirectory);
@@ -12,17 +12,21 @@ namespace SlimJim.Test.Infrastructure
public class CsProjRepositoryTests
{
private const string StartPath = @"C:\Projects";
+ private const string SearchPath1 = @"C:\OtherProjects";
+ private const string SearchPath2 = @"C:\MoreProjects";
private readonly FileInfo file1 = SampleFileHelper.GetCsProjFile("Simple");
private readonly FileInfo file2 = SampleFileHelper.GetCsProjFile("Simple");
private readonly CsProj proj1 = new CsProj {AssemblyName = "Proj1"};
private readonly CsProj proj2 = new CsProj {AssemblyName = "Proj1"};
private ProjectFileFinder finder;
private CsProjReader reader;
private CsProjRepository repository;
+ private SlnGenerationOptions options;
[SetUp]
public void BeforeEach()
{
+ options = new SlnGenerationOptions(StartPath);
finder = MockRepository.GenerateStrictMock<ProjectFileFinder>();
reader = MockRepository.GenerateStrictMock<CsProjReader>();
repository = new CsProjRepository
@@ -32,6 +36,13 @@ public void BeforeEach()
};
}
+ [TearDown]
+ public void AfterEach()
+ {
+ finder.VerifyAllExpectations();
+ reader.VerifyAllExpectations();
+ }
+
[Test]
public void CreatesOwnInstancesOfFinderAndReader()
{
@@ -47,7 +58,7 @@ public void GetsFilesFromFinderAndProcessesThemWithCsProjReader()
reader.Expect(r => r.Read(file1)).Return(proj1);
reader.Expect(r => r.Read(file2)).Return(proj2);
- List<CsProj> projects = repository.LookupCsProjsFromDirectory(StartPath);
+ List<CsProj> projects = repository.LookupCsProjsFromDirectory(options);
Assert.That(projects, Is.EqualTo(new[]{proj1, proj2}));
}
@@ -59,9 +70,20 @@ public void GracefullyHandlesNullsFromReader()
reader.Expect(r => r.Read(file1)).Return(proj1);
reader.Expect(r => r.Read(file2)).Return(null);
- List<CsProj> projects = repository.LookupCsProjsFromDirectory(StartPath);
+ List<CsProj> projects = repository.LookupCsProjsFromDirectory(options);
Assert.That(projects, Is.EqualTo(new[] { proj1 }));
}
+
+ [Test]
+ public void ReadsFilesFromAdditionalSearchPathsAsWell()
+ {
+ options.AdditionalSearchPaths.AddRange(new[] {SearchPath1, SearchPath2});
+ finder.Expect(f => f.FindAllProjectFiles(StartPath)).Return(new List<FileInfo>());
+ finder.Expect(f => f.FindAllProjectFiles(SearchPath1)).Return(new List<FileInfo>());
+ finder.Expect(f => f.FindAllProjectFiles(SearchPath2)).Return(new List<FileInfo>());
+
+ List<CsProj> projects = repository.LookupCsProjsFromDirectory(options);
+ }
}
}
@@ -1,4 +1,3 @@
-using System.Collections.Generic;
using NUnit.Framework;
using SlimJim.Infrastructure;
using SlimJim.Model;
@@ -53,24 +52,29 @@ public void ManyProjectSolution()
TestRender();
}
+ [Test]
+ public void VisualStudio2008Solution()
+ {
+ MakeSolution("VS2008");
+ solution.Version = VisualStudioVersion.VS2008;
+
+ TestRender();
+ }
+
private void MakeSolution(string name, params CsProj[] csProjs)
{
- solution = new Sln
- {
- Name = name,
- Guid = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}",
- Projects = new List<CsProj>(csProjs)
- };
+ solution = new Sln(name, "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}");
+ solution.AddProjects(csProjs);
}
private void TestRender()
{
renderer = new SlnFileRenderer(solution);
- string slnContents = renderer.Render();
- string expected = SampleFileHelper.GetSlnFileContents(solution.Name);
+ string actualContents = renderer.Render();
+ string expectedContents = SampleFileHelper.GetSlnFileContents(solution.Name);
- Assert.That(slnContents, Is.EqualTo(expected));
+ Assert.That(actualContents, Is.EqualTo(expectedContents));
}
}
}
@@ -11,12 +11,14 @@ public class SlnBuilderTests
private string rootProjectName;
private Sln solution;
private ProjectPrototypes projects;
+ private SlnGenerationOptions options;
[SetUp]
public void BeforeEach()
{
projects = new ProjectPrototypes();
rootProjectName = projects.MyProject.AssemblyName;
+ options = new SlnGenerationOptions(@"C:\Projects");
}
[Test]
@@ -27,6 +29,14 @@ public void SlnNameIsEqualToRootProjectName()
}
[Test]
+ public void SlnVersionEqualToVersionFromOptions()
+ {
+ options.VisualStudioVersion = VisualStudioVersion.VS2008;
+ GeneratePartialGraphSolution(new string[0]);
+ Assert.That(solution.Version, Is.EqualTo(VisualStudioVersion.VS2008));
+ }
+
+ [Test]
public void EmptySln()
{
GeneratePartialGraphSolution(new[] { rootProjectName });
@@ -202,7 +212,6 @@ public void MultipleTargetProjects()
private void GeneratePartialGraphSolution(string[] targetProjectNames, params CsProj[] projectsList)
{
var generator = new SlnBuilder(new List<CsProj>(projectsList));
- var options = new SlnGenerationOptions();
Array.ForEach(targetProjectNames, n => options.TargetProjectNames.Add(n));
solution = generator.BuildPartialGraphSln(options);
}
@@ -0,0 +1,15 @@
+using NUnit.Framework;
+using SlimJim.Model;
+
+namespace SlimJim.Test.Model
+{
+ [TestFixture]
+ public class SlnTests
+ {
+ [Test]
+ public void VersionDefaultsTo2010()
+ {
+ Assert.That(new Sln("sln").Version, Is.EqualTo(VisualStudioVersion.VS2010));
+ }
+ }
+}
@@ -0,0 +1,26 @@
+using NUnit.Framework;
+using SlimJim.Model;
+
+namespace SlimJim.Test.Model
+{
+ [TestFixture]
+ public class SolutionGenerationOptionsTests
+ {
+ [Test]
+ public void SolutionOutputPathDefaultsToProjectsRootPath()
+ {
+ var options = new SlnGenerationOptions(@"C:\Projects");
+
+ Assert.That(options.SlnOutputPath, Is.EqualTo(options.ProjectsRootDirectory));
+ }
+
+ [Test]
+ public void SolutionOutputPathUsesGivenValueIfSet()
+ {
+ string slnOutputPath = @"C:\Projects\Solutions";
+ var options = new SlnGenerationOptions(@"C:\Projects") {SlnOutputPath = slnOutputPath};
+
+ Assert.That(options.SlnOutputPath, Is.EqualTo(slnOutputPath));
+ }
+ }
+}
@@ -0,0 +1,10 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+
+
+Global
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -58,6 +58,8 @@
<Compile Include="Infrastructure\ProjectFileFinderTests.cs" />
<Compile Include="Infrastructure\SlnFileRendererTests.cs" />
<Compile Include="Model\ProjectPrototypes.cs" />
+ <Compile Include="Model\SlnTests.cs" />
+ <Compile Include="Model\SolutionGenerationOptionsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SampleFiles\SampleFileHelper.cs" />
<Compile Include="Model\SlnBuilderTests.cs" />
@@ -85,6 +87,7 @@
<Content Include="SampleFiles\SampleFileSystem\Theirs\TheirProject1\TheirProject1.csproj" />
<Content Include="SampleFiles\SampleFileSystem\Theirs\TheirProject2\TheirProject2.csproj" />
<Content Include="SampleFiles\SampleFileSystem\Theirs\TheirProject3\TheirProject3.csproj" />
+ <Content Include="SampleFiles\Sln\VS2008.sln" />
<Content Include="SampleFiles\Sln\ManyProjects.sln" />
<Content Include="SampleFiles\Sln\ThreeProjects.sln" />
<Content Include="SampleFiles\Sln\BlankSolution.sln" />
@@ -18,7 +18,7 @@ public class SlnFileGeneratorTests
private SlnBuilder slnBuilder;
private SlnGenerationOptions options;
private readonly List<CsProj> projects = new List<CsProj>();
- private readonly Sln createdSlnObject = new Sln();
+ private readonly Sln createdSlnObject = new Sln("Sln");
[SetUp]
public void BeforeEach()
@@ -34,7 +34,7 @@ public void BeforeEach()
};
SlnBuilder.OverrideDefaultBuilder(slnBuilder);
- options = new SlnGenerationOptions { ProjectsRootDirectory = ProjectsDir };
+ options = new SlnGenerationOptions(ProjectsDir);
}
[Test]
@@ -50,7 +50,7 @@ public void GeneratesSlnFileForGivenOptions()
{
options.TargetProjectNames.Add(TargetProject);
- repo.Expect(r => r.LookupCsProjsFromDirectory(ProjectsDir)).Return(projects);
+ repo.Expect(r => r.LookupCsProjsFromDirectory(options)).Return(projects);
slnBuilder.Expect(bld => bld.BuildPartialGraphSln(options)).Return(createdSlnObject);
slnWriter.Expect(wr => wr.WriteSlnFile(createdSlnObject, ProjectsDir));
View
Binary file not shown.
@@ -15,10 +15,7 @@ public static SlnGenerationOptions BuildOptions(string[] args, string workingDir
private SlnGenerationOptions Build(string[] args, string workingDirectory)
{
- options = new SlnGenerationOptions
- {
- ProjectsRootDirectory = workingDirectory
- };
+ options = new SlnGenerationOptions(workingDirectory);
ProcessSwitches(args);
@@ -71,10 +68,11 @@ private void ProcessSwitch(string arg)
private VisualStudioVersion TryParseVersionNumber(string versionNumber)
{
- VisualStudioVersion parsedVersion;
- if (!Enum.TryParse("_" + versionNumber, out parsedVersion))
+ VisualStudioVersion parsedVersion = VisualStudioVersion.ParseVersionString(versionNumber);
+
+ if (parsedVersion == null)
{
- parsedVersion = VisualStudioVersion._90;
+ parsedVersion = VisualStudioVersion.VS2010;
}
return parsedVersion;
@@ -12,9 +12,29 @@ public CsProjRepository()
Reader = new CsProjReader();
}
- public virtual List<CsProj> LookupCsProjsFromDirectory(string rootDirectory)
+ public virtual List<CsProj> LookupCsProjsFromDirectory(SlnGenerationOptions options)
+ {
+ List<FileInfo> files = FindAllProjectFiles(options);
+
+ List<CsProj> projects = ReadProjectFilesIntoCsProjObjects(files);
+
+ return projects;
+ }
+
+ private List<FileInfo> FindAllProjectFiles(SlnGenerationOptions options)
+ {
+ List<FileInfo> files = Finder.FindAllProjectFiles(options.ProjectsRootDirectory);
+
+ foreach (string path in options.AdditionalSearchPaths)
+ {
+ files.AddRange(Finder.FindAllProjectFiles(path));
+ }
+
+ return files;
+ }
+
+ private List<CsProj> ReadProjectFilesIntoCsProjObjects(List<FileInfo> files)
{
- List<FileInfo> files = Finder.FindAllProjectFiles(rootDirectory);
List<CsProj> projects = files.ConvertAll(f => Reader.Read(f));
projects.RemoveAll(p => p == null);
return projects;
@@ -4,6 +4,6 @@ namespace SlimJim.Model
{
public interface ICsProjRepository
{
- List<CsProj> LookupCsProjsFromDirectory(string rootDirectory);
+ List<CsProj> LookupCsProjsFromDirectory(SlnGenerationOptions options);
}
}
Oops, something went wrong.

0 comments on commit 132ee2e

Please sign in to comment.