In order to automate the package and deployment process I used SourceCode.Deployment.Management dll to create the deployment package using the following code:
Session session = _packageDeploymentManager.CreateSession("K2Module" + DateTime.Now.ToString()); session.SetOption("NoAnalyze", true); PackageItemOptions options = PackageItemOptions.Create(); options.ValidatePackage = Validate; var pathNamespace = "/root/"; var rootNamespace = "urn:SourceCode/Categories"; string ns; string category; var categories = Category.Split(''); if (categories.Length > 1) { var parentCats = string.Join("/", categories.Take(categories.Length - 1)); pathNamespace += parentCats + "/"; } category = categories.Last(); ns = rootNamespace + "?" + Uri.EscapeDataString(category) + "#Path." + Uri.EscapeDataString(pathNamespace); var typeRef = new TypeRef(category, ns); var query = QueryItemOptions.Create(typeRef); var results = session.FindItems(query).Result; foreach (var result in results) { options.Include(result, PackageItemMode.IncludeDependencies); } options.PackageItemMode = IncludeDependenciesAsReference ? PackageItemMode.IncludeDependenciesAsReference : PackageItemMode.IncludeDependencies; session.PackageItems(options); var fileStream = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); session.Model.Save(fileStream); fileStream.Close(); _packageDeploymentManager.CloseSession(session.Name);
but I couldn't deploy the genrated package, becuase of error "This version was created on version is no longer suppoerded on this target environment", Actually I'm using K2 five and all dlls I'm using from inside the environment itself.