2

我正在研究 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));
        }
    }
4

1 回答 1

2

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

是否可以为完整版本的 .Net 4 而不是客户端配置文件构建?

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

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

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

于 2011-09-19T00:38:56.333 回答