c# - 无法使用 Microsoft.Build 库发布网站

标签 c# msbuild

我目前正在尝试编写一个将用作自动发布过程的应用程序。在此过程中,我需要构建和发布一些项目。我能够成功构建和发布 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

然后它在构建时失败。

最佳答案

如果您以这种方式创建构建参数,您可以在控制台上显示构建输出:

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构建和发布工作正常。

关于c# - 无法使用 Microsoft.Build 库发布网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27032940/

相关文章:

c# - 是否有 Windows 7 文件夹位置控件或是否需要自定义代码?

c# - .NET MongoDB 连接的最佳实践?

msbuild - 如何使用 MSDeploy 配置应用程序池

iis-7 - AppPool 已停止时如何防止出现错误消息

msbuild - 使用 msdeploy 和 Visual Studio 2012 构建一次并部署到多个环境

msbuild - .nu​​spec 文件中的 Packages.config 与 Dependency 部分

c# - XmlNode 值与 InnerText

c# - Razor 页面 : Inheritance of a model to add fields during creation

c# - MailKit 和同一邮件帐户上的多个客户端

msbuild - 创建 MSBuild 目标 Hook