我正在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 /电话号码:环境=发展如何进行K2自动部署并与持续集成工具(TeamCity)集成?
之前,我运行的MSBuild,我需要创建K2部署包第一,现在问题来了:
1.我没有发现有命令具有相同功能的“创建K2部署包“Visual Studio;
2.我只发现我可以使用编码创建包,所以我尝试创建一个控制台应用程序创建K2部署包。代码需要引用Microsoft.Build DLL,但不支持将Microsoft.Build引用添加到Console项目。所以我尝试创建一个类项目,并将下面的代码放到类中,类成功复杂化,但是当我尝试将此类项目或DLL添加到控制台项目时,它仍然存在相同的问题。我得到了关于System.Design,Microsoft.Build,Microsoft.Build.Framework和Microsoft.Build.Utilities的4个警告。我没有找到一种方法来通过控制台运行create package方法。
您是否有更好的主意或解决方案来解决K2自动部署问题?
错误信息:
引用的程序集 “... \ BIN \调试\ DeployPackageCreator.dll” 无法得到解决,因为它的“System.Design的依赖,版本= 4.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a“,它不在当前的目标框架”.NETFramework,Version = v4.0,Profile = Client“中。请删除不在目标框架中的组件的引用,或考虑重新定位您的项目。
代码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));
}
}
假设他是用最近的K2 blackpearl的版本,他可以建立的.NET 4.0的完整版工作流程(过程定义)如果目标K2 blackpearl服务器配置为使用.NET 4. K2文档包含有关如何配置服务器以支持.NET 4的说明。0组件。 – codewise