Home > Plug-in Development > How to add new projects to a solution programmatically using DXCore

How to add new projects to a solution programmatically using DXCore

April 19th, 2012

You can add new projects from the Visual Studio built-in project templates to the current solution using the DXCore Solution service:

CodeRush.Solution.AddProject("ProjectTemplateName", "UniqueProjectName");

The AddProject method takes two arguments:

  • The name of the Visual Studio project template (zipped), e.g. “ClassLibrary.zip”. To learn more about template names, you can observe the Visual Studio installation directory where templates are located:

%ProgramFiles%\Microsoft Visual Studio %Version%\Common7\IDE\ProjectTemplates\%Language%\Windows\1033\

where %Language% is CSharp or VisualBasic and %Version% is the version of Visual Studio you use.

  • The unique name of the project to create and add to the current solution.

To add existing files to a solution, refer to the following topics:

If you don’t have an existing file, you can write it using the usual System.IO.StreamWriter class and then the methods described in the links above, to add it to the project. Here are several methods that might be useful when creating a new file.

First, you may require a unique file name. The ProjectElement (CodeRush. Source. ActiveProject) instance has the special GenerateUniqueBaseFileName() method. The method generates a unique base file name. All of the projects disk files are checked against the given base file name to ensure that it is unique. If it is not, a unique base file name is generated. The method takes the base name and optionally, an extension of a file name as parameters.

To get the list of possible extensions for the specific language, use the DXCore Language service and its GetSupportedFileExtensions() method:

string extensions = CodeRush.Language.GetSupportedFileExtensions("CSharp");

The returned string is a list of extensions split by a semicolon character. Most times, it is a string with a single extension, e.g. “.cs” for CSharp language.

Products: DXCore
Versions: 11.2 and up
VS IDEs: 2008 and up
Updated: Apr/19/2012
ID: D144

Similar Posts: