我正在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