How to do K2 auto deployment and integrate with Continuous Integration Tool (TeamCity)?

StackOverflow https://stackoverflow.com/questions/7462622

  •  22-01-2021
  •  | 
  •  

Domanda

I am working on K2 blackpearl project (Visual Studio 2010+K2 blackpearl+SQL Server 2008). The entire source code in SVN, and I am using the TeamCity as the continuous integration tool. I completed the Web and database auto deployment. When I am working on the K2 auto deployment, I use the MSBuild to deploy the K2 package to K2 server

Msbuild ”Project Working Folder\obj\Debug\Deployment\ WorkflowName.msbuild" /p:TestOnly=True /p:Environment=Development

Before I run the MSBuild, I need to create the K2 deployment package first, now the problem coming:
1. I didn’t found the command have the same function with “Create K2 Deployment package” of Visual Studio;
2. I only found I can use the coding to create the package, so I try to create a Console application to create the K2 deployment package. The code need to refer to Microsoft.Build DLL, but it is not support to add the Microsoft.Build reference to a Console project. So I try to create a class project, and put below code to the class, the class complicate successfully, but when I try to add this class project or DLL to the console project, it is still have the same problem. I got 4 warning about System.Design, Microsoft.Build, Microsoft.Build.Framework and Microsoft.Build.Utilities. I didn’t found a way to run the create package method by Console.

Do you have better idea or solution to resolve the K2 auto deployment issues?

Error information:
The referenced assembly "…\bin\Debug\DeployPackageCreator.dll" could not be resolved because it has a dependency on "System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.

Code deails:

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using SourceCode.ProjectSystem;
using SourceCode.Workflow.Authoring;
using SourceCode.Framework.Deployment;
using System.IO; 
using SourceCode.EnvironmentSettings.Client;



public string K2ConnectionString { get; set; }
public string SelectedEnvironment { get; set; }
public string OutputFolder { get; set; }
public string KPRXLocation { get; set; }
public string FolderName { get; set; }



private void SavePackage(string folderName, string kprxLocation, string outputFolder)
    {
        //Create a project to use for deployment, the project is the folder/solution
        string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
        Project project = new Project(folderName, tmpPath);

        //Add the process as a projectfile.
        Process processToDeploy = Process.Load(kprxLocation);

        // Log load problems.
        foreach (SourceCode.Framework.ObjectLoadException loadExceptions in processToDeploy.LoadErrors)
        {
            //Log.LogWarning("Load exception: {0}", loadExceptions.Message);
        }

        // Add process to the project.
        AddProcess(project, processToDeploy);

        //Do a test-compile
        if (!TestCompile(project))
        {
            throw new Exception("First compile test; Project did not compile.");
        }

        // create a deployment package
        DeploymentPackage package = project.CreateDeploymentPackage();

        // Add environment stuff
        AddEnvironment(package, this.SelectedEnvironment);

        //Set other connections. The K2 deployment package uses a reference. This does the same but does not use the reference!
        package.SmartObjectConnectionString = this.K2ConnectionString;
        package.WorkflowManagementConnectionString = this.K2ConnectionString;

        //Do a test-compile
        if (!TestCompile(project))
        {
            throw new Exception("Second compile test; Project did not compile.");
        }

        //Finaly, save the deployment package
        package.Save(outputFolder, folderName);
    }


   private bool TestCompile(Project project)
    {
       // project.Environment.AuthoringMode = SourceCode.Framework.AuthoringMode.CodeOnly;
        //Log.LogMessage("Project.environment: {0}", project.Environment.Name);
        DeploymentResults compileResult = project.Compile();

        if (!compileResult.Successful)
        {
            foreach (System.CodeDom.Compiler.CompilerError error in compileResult.Errors)
            {
                string errString = string.Format("Error compiling: {0} - {1}", error.ErrorNumber, error.ErrorText);
                //Log.LogWarning(errString);
                Console.WriteLine(errString);
            }
        }

        return compileResult.Successful;
    }



private void AddProcess(Project project, Process process)
    {
        // Create the ProjectFile
        ProjectFile file = (ProjectFile)project.CreateNewFile();

        // Set information on the file.
        file.FileName = process.FileName;
        file.Content = process;

        // Add the file to the project
        project.Files.Add(file);

        // Save the project to the temp location.
        project.SaveAll();
    }



    private void AddEnvironment(DeploymentPackage package, string SelectedEnvironment)
    {
        // Since there's no documentation on connecting to the environment server. This seems to work....
        EnvironmentSettingsManager envManager = new EnvironmentSettingsManager(true);
        envManager.ConnectToServer(this.K2ConnectionString);
        envManager.InitializeSettingsManager(true);
        envManager.Refresh();

        // Add environments + environment properties.
        foreach (EnvironmentTemplate envTemp in envManager.EnvironmentTemplates)
        {
            foreach (EnvironmentInstance envInst in envTemp.Environments)
            {
                //Add an environment to the package.
                DeploymentEnvironment env = package.AddEnvironment(envInst.EnvironmentName);
                foreach (EnvironmentField field in envInst.EnvironmentFields)
                {
                    env.Properties[field.FieldName] = field.Value;
                }

                // Make sure the environment we select actually exists.
                if (envInst.EnvironmentName == SelectedEnvironment)
                {
                    package.SelectedEnvironment = envInst.EnvironmentName;
                }
            }
        }

        //Cleanup
        envManager.Disconnect();
        envManager = null;

        //Final check of the selected environment 
        if (package.SelectedEnvironment == null || package.SelectedEnvironment == string.Empty)
        {
            throw new Exception(string.Format("Could not find the environment you wanted to select ({0})", SelectedEnvironment));
        }
    }
È stato utile?

Soluzione

This error appears to be caused by you building your deployment package (which has a dependency on System.Design) using the ".Net 4.0 Client profile" (not the full version of the framework) which does not include the framework library System.Design.

Is it possible to build for the full version of .Net 4 instead of the Client Profile?

While i am not fully aware of the platform K2 runs on, if it is a Sharepoint library/package then i'd assume that the server it was running on had the full version of .net 4 installed.

Information about the Client Profile limitations over on MSDN:

http://msdn.microsoft.com/en-us/library/cc656912.aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top