2012-08-22 76 views
2

我想構建一個VS2008項目(ASP.NET Web應用程序),然後使用Microsoft.Build.Engine進行發佈。使用Microsoft.Build.Engine使用c#構建和發佈(ASP.NET Web應用程序)#

到目前爲止,我已成功設法成功完成項目。

但我無法將其發佈到指定的目錄。

我的構建方法是:

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

我的發佈方法是:

private void PublishProject() 
{ 

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

} 

任何想法?

回答

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

} 
1

這些是我設置發佈我的項目的屬性。

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

不知道在哪裏設置這些......這些都不是引擎類的屬性,也不BuildPropertyGroup的性質......可以請你在小細節解釋如何做到發佈? –

+0

嗨...我想我明白了你的意思......我將在下面發佈完整的工作方法...... :) –

+0

對不起,以前沒有看到這一點。我很高興你明白了。乾杯! –

相關問題