locked
Programmatically Publish Web Application RRS feed

  • Question

  • I currently am using this code to programmatically build a solution.  The build part works great, but how would I go about publishing some of the projects in the solution after the build completes?

     

    				string projectFileName = directoryPath + @"\WebApp.sln";
    				ProjectCollection projectCollection = new ProjectCollection();
    				Dictionary<string, string> globalProperty = new Dictionary<string, string>();
    				globalProperty.Add("Configuration", "Release");
    				globalProperty.Add("Platform", "Any CPU");
    
    				BuildRequestData buildRequestData = new BuildRequestData(projectFileName, globalProperty, null, new string[] { "Build" }, null);
    				BuildParameters buildParameters = new BuildParameters(projectCollection);
    				buildParameters.Loggers = new List<Logger>() { new KBBuilderLogger() { Parameters = @"c:\Build\buildlog.txt" } };
    				BuildResult buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData);
    

     


    Thursday, March 24, 2011 7:51 PM

Answers

  • I figured out how to do this.  In my code I created a new method that runs a process, and the command that is passed to that process is below.  DirectoryPath is the local folder, and project folder is website.  Publish location is where I want it to go.  This is for a Web Site, I haven't tried it for a Web Application.

    "aspnet_compiler -nologo -v / -p \"" + directoryPath + "\\" + projectFolder + "\" -u \"" + publishLocation + "\\" + projectFolder + "\"";
    
    • Marked as answer by NickBrett Wednesday, March 30, 2011 6:00 PM
    Wednesday, March 30, 2011 1:42 PM

All replies

  • Hi NickBrett,

     

    Thanks for your post.

    As far as I know, there is no API for publishing web applications.

    As a workaround, you can involve a "Deploy" target into your web application project as below, you can put it into "Afterbuild" target.

    <Target Name="Deploy">
        <ItemGroup>
          <BinFiles Include="$(WebProjectFolder)\bin\*.*;"/>
        </ItemGroup>
      
        <CreateItem
          Include="@(Content->'$(WebProjectFolder)\%(RelativeDir)%(Filename)%(Extension)')"
          AdditionalMetadata="Dir=%(RelativeDir)">
          <Output TaskParameter="Include" ItemName="contentFiles"/>
        </CreateItem>
        
        <Copy  SourceFiles="@(contentFiles)"
         DestinationFiles="@(contentFiles->'$(BuildFolderWeb)\%(Dir)%(Filename)%(Extension)')"
         ContinueOnError="false"/>
        
        <Copy  SourceFiles="@(BinFiles)"
        DestinationFiles="@(BinFiles->'$(BuildFolderWeb)\bin\%(RecursiveDir)%(Filename)%(Extension)')"
        ContinueOnError="true"/>
    </Target>
    
    
    

    If I misunderstand your issue, be free to let me know.


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 25, 2011 3:38 AM
  • Hi Victor,

    That's not exactly what I'm looking to do.  I don't have an MSBuild project, and don't want to create one.  What I'm trying to accomplish is a nightly task to get code from TFS, build it and then deploy that code to our development web severs.  I was hoping there was a way to automate the right click -> Publish functionality in Visual Studio.  Perhaps I should post in a Visual Studio forum and not MSBuild?

    Friday, March 25, 2011 12:16 PM
  • Hi NickBrett,

    Thanks for your feedback.

    I'm also working on Visual Studio Forum, and as far as I know,

    you can only trigger right click -> Publish functionality by VS extensibility Api,

    which means you cannot make it work in an external application but make a macro or addin to achieve that.

     http://msdn.microsoft.com/en-us/library/b4c73967.aspx 

     http://msdn.microsoft.com/en-us/library/5abkeks7.aspx 

    with

    DTE.ExecuteCommand("Build.PublishSelection")

    Hope my reply helps resolve your issue.

     Best Regards,

    Ziwei Chen

     

     

     

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Victor_Chen Wednesday, March 30, 2011 6:03 AM
    Monday, March 28, 2011 3:08 AM
  • Hi Victor,

    Thanks for the reply.  That's very disappointing something like this can't be automated.

    Nick

    Tuesday, March 29, 2011 1:48 PM
  • Thanks for understanding.
    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 30, 2011 6:03 AM
  • I figured out how to do this.  In my code I created a new method that runs a process, and the command that is passed to that process is below.  DirectoryPath is the local folder, and project folder is website.  Publish location is where I want it to go.  This is for a Web Site, I haven't tried it for a Web Application.

    "aspnet_compiler -nologo -v / -p \"" + directoryPath + "\\" + projectFolder + "\" -u \"" + publishLocation + "\\" + projectFolder + "\"";
    
    • Marked as answer by NickBrett Wednesday, March 30, 2011 6:00 PM
    Wednesday, March 30, 2011 1:42 PM
  • Thanks for sharing the solution.
    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 31, 2011 3:35 AM
  • Is it possible to pre-compile the web app by adding following? 
    globalProperty.Add("PrecompileBeforePublish", "true");

    • Edited by BandRa Wednesday, August 9, 2017 3:15 PM
    Wednesday, August 9, 2017 3:14 PM