posted on Thursday, February 03, 2005 10:52 AM
by
johnwood
SolGen: C# Solution Generator v0.1
Bottom Line:
Download a free C# solution file generator here, that attempts to turn any C# project file into a buildable solution (sln) file.
Introduction
After getting tired of tweaking solution (.sln) files and project references to create buildable solution files, I decided to write a utilty to do this for me. The result is SolGen.
SolGen is a utility that takes any C# project file and generates a buildable Visual Studio solution (.sln file), containing that project and all its dependencies (and their dependencies and so on). It also updates each of the projects' references to point to the projects in the solution. By running this command line tool on the project you end up with a solution that you can instantly build, without having to worry about locating dependencies or updating references manually.
Background
There are lots of issues with solution files in Visual Studio. I've heard a lot of complaints about HintPaths having full or incorrect paths, often where the HintPath points to one particular release (Debug) but the build is to target Release causing a mismatch of DLLs. While the projects may exist in the solution, Visual Studio does not always pick up the projects and update references, leaving you to manually remove and re-add any references that show up with triangles.
Using this simple tool you can automate the creation of a very straightforward build process, without having to worry about creating a build script yourself. The utility intelligently locates projects and effectively creates a build script for you. Once the solution is created, just run devenv.exe, passing in your file and "/build" to build, and your build procedure is complete. You can also specify whether you want a debug or release build, and can even schedule it as a process and have it email the result of the build every night.
How It Works
The SolGen utility works by parsing the content of the main project, and any projects under the specified folder. It collects information on the GUID, AssemblyName and references of each project file. It then uses this to determine, by assemblyName, which references are actually pointing to which projects. It then updates the references to point to the project GUID rather than the HintPath. The GUID is required for the project to be recognized by references when it is part of the solution.
The utility then determines the dependencies of the project and generates a solution of all the projects required to build the main output.
Usage Guidelines
SolGen is a command-line tool, so you should invoke it from the dos prompt. When you run SolGen you will be presented with a list of options for running the utility.
Use: solgen projectfile.csproj [solfile.sln c:\folder]
The most important parameter you will supply is the project file. Given only a project file, it can generate a solution with the same name as the project (but the SLN extension), and look for all C# projects in the parent folder downwards. If you want to override the solution name, and the folder in which to look for other projects, you can supply those parameters.
When the utility completes, it would have generated a separate project file for each project, designed to be used within the solution. This is required because the references in the project can only be set to the project GUID if the project is to be used as part of the solution. Modifying the original project would render that project unusable outside of that (or a similar) solution. So instead it creates a new project file, with a _buildver suffix, along side the original project.
Finally it will create a solution file referencing all the _buildver.csproj files. You should then be able to open the solution and build the product.
If you want to help me test the utility you can download it here. I will provide the source code once it is stable if anybody is interested. Keep in mind you're using this at your own risk seeing as it's beta software.
If you have any problems/questions/suggestion please let me know.. otherwise happy testing and I hope you find it useful.