2

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 ???

M. Ali Iftikhar
  • 3,125
  • 2
  • 26
  • 36

2 Answers2

4
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();

}
M. Ali Iftikhar
  • 3,125
  • 2
  • 26
  • 36
1

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

    DeployOnBuild=true;
    DeployTarget=Package;
    _PackageTempDir=$(PackagePath)
Chris Martin
  • 1,871
  • 16
  • 17