我目前正在尝试编写一个可用作自动发布过程的应用程序。在这个过程中,我需要构建并发布一些项目。我能够成功构建和发布Web应用程序,但是,在发布网站时,我遇到了问题。
我能够通过以下命令行执行成功完成所需的操作:
msbuild website.publishproj /p:deployOnbuild=true /p:PublishProfile="test.pubxml"
我试图通过使用构建库来执行它,但它失败了:
string projectFileNamepub = CurrentPublish.ExcaliburBuildPath;
Dictionary<string, string> GlobalPropertypub = new Dictionary<string, string>();
ProjectCollection pcpub = new ProjectCollection();
//pcpub.SkipEvaluation = true;
//GlobalPropertypub.Add("Configuration", "Release");
//GlobalPropertypub.Add("Platform", "x86");
GlobalPropertypub.Add("DeployOnBuild", "true");
GlobalPropertypub.Add("PublishProfile",CurrentPublish.ExcaliburPublishProfile);
//GlobalPropertypub.Add("VisualStudioVersion", "11.0");
BuildRequestData BuildRequestpub = new BuildRequestData(projectFileNamepub, GlobalPropertypub, null, new string[] { "Build" }, null);
BuildResult buildResultpub = BuildManager.DefaultBuildManager.Build(new BuildParameters(pcpub), BuildRequestpub);
if (buildResultpub.OverallResult == BuildResultCode.Success)
{
bsuccess = true;
txtOutput.Text = txtOutput.Text + "Publish Success \n";
}
注释掉的属性是我尝试使用的属性,但都没有成功。
我做错了吗?我已经使用了这个在此之前发布另一个Web应用程序,并且它成功完成。
此目标成功完成:
_CheckForInvalidConfigurationAndPlatform
然后在Build上失败。
答案 0 :(得分:2)
如果以这种方式创建构建参数,则可以在控制台上显示构建输出:
var buildParameters = new BuildParameters(pc)
{
Loggers = new List<Microsoft.Build.Framework.ILogger> { new ConsoleLogger() }
};
当我这样做时,我看到以下错误:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4353,5): error MSB4127: The "GetPublishingLocalizedString" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Web.Publishing.Tasks.GetPublishingLocalizedString' to type 'Microsoft.Build.Framework.ITask'.
我搜索了error MSB4127
并在此处找到了答案:MSBuild "GenerateFakes" Error MSB4127, MSB4060
我已经指定了VisualStudioVersion
。我只是将<runtime>
中的C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.config
部分添加到我的App.config
中,并且构建和发布工作正常。