bothmanity
bothmanity

Reputation: 41

Unable to publish Website Using Microsoft.Build Library

I am currently attempting write an application that will function as an automatic publishing process. In the process, I need to build, and publish a number of items. I am able to build, and publish the web application successfully, however, when publishing the website, I am running into problems.

I am able to successfully complete the required with the following command line execution:

msbuild website.publishproj /p:deployOnbuild=true /p:PublishProfile="test.pubxml"

I am trying to execute this by using the build libraries, but it is failing:

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";
        }

The commented out properties are properties that I have attempted to use, but none of them were successful.

Is there something that I am doing wrong? I have used exactly this to publish another web application before this one, and it completes successfully.

This target completes successfully:

_CheckForInvalidConfigurationAndPlatform

It then fails on Build.

Upvotes: 4

Views: 574

Answers (1)

Gary Hopkins
Gary Hopkins

Reputation: 21

If you create your build parameters this way you can display the build output on the console:

var buildParameters = new BuildParameters(pc)
{
    Loggers = new List<Microsoft.Build.Framework.ILogger> { new ConsoleLogger() }
};

When I did this I saw the following error:

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'.

I searched for error MSB4127 and found the answer here: MSBuild "GenerateFakes" Error MSB4127, MSB4060

I was already specifying the VisualStudioVersion. I simply added the <runtime> section from C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.config into my App.config and the build and publish worked.

Upvotes: 2

Related Questions