【问题标题】:How to do K2 auto deployment and integrate with Continuous Integration Tool (TeamCity)?如何进行 K2 自动部署并与持续集成工具 (TeamCity) 集成?
【发布时间】:2011-09-18 15:56:31
【问题描述】:

我正在开发 K2 blackpearl 项目(Visual Studio 2010+K2 blackpearl+SQL Server 2008)。 SVN 中的整个源代码,我使用 TeamCity 作为持续集成工具。我完成了 Web 和数据库的自动部署。当我处理 K2 自动部署时,我使用 MSBuild 将 K2 包部署到 K2 服务器

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

在运行 MSBuild 之前,我需要先创建 K2 部署包,现在问题来了:
1. 没有发现该命令与Visual Studio的“创建K2部署包”功能相同;
2、我只发现可以使用编码创建包,所以我尝试创建一个控制台应用程序来创建K2部署包。代码需要引用 Microsoft.Build DLL,但不支持将 Microsoft.Build 引用添加到 Console 项目中。所以我尝试创建一个类项目,并将下面的代码放入类中,类复杂化成功,但是当我尝试将这个类项目或DLL添加到控制台项目时,它仍然有同样的问题。我收到 4 个关于 System.Design、Microsoft.Build、M​​icrosoft.Build.Framework 和 Microsoft.Build.Utilities 的警告。我没有找到通过控制台运行创建包方法的方法。

您有更好的想法或解决方案来解决 K2 自动部署问题吗?

错误信息:
无法解析引用的程序集“...\bin\Debug\DeployPackageCreator.dll”,因为它依赖于“System.Design,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”,这不在当前目标中框架“.NETFramework,Version=v4.0,Profile=Client”。请删除对不在目标框架中的程序集的引用或考虑重新定位您的项目。

代码说明:

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));
        }
    }

【问题讨论】:

    标签: deployment msbuild k2


    【解决方案1】:

    此错误似乎是由于您使用“.Net 4.0 客户端配置文件”(不是框架的完整版本)构建部署包(依赖于 System.Design)引起的其中不包括框架库 System.Design

    是否可以为 .Net 4 的完整版本而不是 Client Profile 构建?

    虽然我不完全了解 K2 运行的平台,但如果它是 Sharepoint 库/包,那么我会假设它运行的服务器安装了完整版本的 .net 4。

    有关 MSDN 上的客户端配置文件限制的信息:

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

    【讨论】:

    • 假设他使用的是最新版本的 K2 blackpearl,如果目标 K2 blackpearl 服务器配置为使用 .NET 4,他可以为完整版本的 .NET 4.0 构建工作流(流程定义)。 K2 文档包含有关如何配置服务器以支持 .NET 4.0 程序集的说明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 2010-09-16
    • 2011-08-10
    • 2013-10-17
    • 1970-01-01
    • 2016-08-28
    相关资源
    最近更新 更多