Loading a project file through code

This content applies to legacy components (such as K2 Studio and K2 for Visual Studio), legacy assemblies, legacy services or legacy functionality. If you have upgraded from K2 blackpearl 4.7 to K2 Five, these items may still be available in your environment. These legacy items may not be available in new installations of K2 Five. These legacy items may also not be available, supported, or behave as described, in future updates or versions of K2. Please see the legacy component support policy for more information about support for these components.

The code sample below demonstrates a method of loading a K2 project file using code.

This code sample requires a class reference to the assemblies:

  • SourceCode.Framework.dll

and project references to
  • Microsoft.Build.Framework

//set the path to the K2 project file to load
string filename = "[K2ProjectFilePath.kprx]";
SourceCode.ProjectSystem.Project project = new Project();
project.Load(filename);
//load the .kprx files in the project recursively and iterate over them
foreach(SourceCode.ProjectSystem.ProjectFile file in project.GetAllFiles("kprx", true)) {
 //do something, e.g. read the file path of each .kprx file
 string filePath = file.FullFileName;
}