Build and Publish (ASP.NET Web Application) using Microsoft.Build.Engine using c#

786 Views Asked by At

I want to Build a VS2008 project (ASP.NET Web Application) and then publish using Microsoft.Build.Engine.

I have so far successfully managed to BUild the project.

But i am unable to Publish it to a specified directory.

My build method is:

private void BuildProject()
{
            Engine engine = new Engine();
            FileLogger logger = new FileLogger();
            logger.Parameters = @"logfile=C:\temp\build.log";
            engine.RegisterLogger(logger);

            BuildPropertyGroup bpg = new BuildPropertyGroup();
            bpg.SetProperty("Configuration", "Debug");
            bpg.SetProperty("Platform", "AnyCPU");

            bool success = engine.BuildProjectFile(GetProjectFileName(), null, bpg);

            if (success)
                Console.WriteLine("Success!");
            else
                Console.WriteLine("Build failed - look at c:\temp\build.log for details");

            engine.UnloadAllProjects();
            engine.UnregisterAllLoggers();
}

And my publish method is:

private void PublishProject()
{

           //no idea what goes here ... please help !!!

}

Any ideas ???

2

There are 2 best solutions below

0
On BEST ANSWER
private void PublishProject()
{

Engine engine = new Engine();
            FileLogger logger = new FileLogger();
            logger.Parameters = @"logfile=C:\temp\publish.log";
            engine.RegisterLogger(logger);

            BuildPropertyGroup bpg = new BuildPropertyGroup();
            bpg.SetProperty("OutDir", @"C:\outdir\");
            bpg.SetProperty("Configuration", "Debug");
            bpg.SetProperty("Platform", "AnyCPU");
            bpg.SetProperty("DeployOnBuild", "true");
            bpg.SetProperty("DeployTarget", "Package");
            bpg.SetProperty("PackageLocation", @"$(OutDir)\MSDeploy\Package.zip");
            bpg.SetProperty("_PackageTempDir", @"C:\temp\");


            bool success = engine.BuildProjectFile(GetProjectFileName(), null, bpg);

            if (success)
                Console.WriteLine("Success!");
            else
                Console.WriteLine(@"Build failed - look at c:\temp\publish.log for details");

            engine.UnloadAllProjects();
            engine.UnregisterAllLoggers();

}
3
On

These are the properties I set to publish a project of mine.

    DeployOnBuild=true;
    DeployTarget=Package;
    _PackageTempDir=$(PackagePath)