« Previous Next »

Thread: MSDeploy API with asp.net 2.0

Last post 11-02-2009 12:53 PM by LearningIIS7. 9 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (10 items)

Sort Posts:

  • 10-26-2009, 10:27 AM

    MSDeploy API with asp.net 2.0

    I am using Microsoft web deployment tool apis (microsoft.web.deployment.dll) in my application in order to sync two servers. However, I am not finding any support for logging ability (msdeploy automatically logs the changes done in a log file when run from the command prompt)

     

    Is it not possible to have msdeploy also log the changes when I am using it from within a asp.net 2.0 application?

  • 10-26-2009, 1:17 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    To log using the API you can handle the trace events provided. A simple example would be:

    DeploymentBaseOptions SrcBaseOptions = new DeploymentBaseOptions();SrcBaseOptions.Trace += this.TraceEventHandler;

    SrcBaseOptions.TraceLevel = TraceLevel.Info;

    ... and define the traceeventhandler as follows:

    private void TraceEventHandler(object sender, DeploymentTraceEventArgs traceEvent)

    {

    WriteEvent(traceEvent);

    }

    private void WriteEvent(DeploymentTraceEventArgs e)

    {

    TraceLevel traceLevel = e.EventLevel;

    Console.WriteLine(e.Message);

    }

  • 10-26-2009, 4:57 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    Hello Moshaikh,

    Thanks so much for the prompt response. It is very much appreciated.

    I am having problem with the following line from the code you wrote above

    SrcBaseOptions.Trace += this.TraceEventHandler;

    VB.net compiler wouldn't let me compile this...it says

    Public Event Trace (Sender as object, e as microsoft.web.deployment.deploymenttraceEventArgs) is an event and cannot be aclled directly. Use a RaiseEvent statement to raise an event.

    My code is in vb.net...so I would really appreciate if you could help me in this respect

    RaiseEvent Trace(Me.TraceEventHandler)....is this the right way to translate the coding SrcBaseOptions.Trace += this.TraceEventHandler;

  • 10-26-2009, 5:21 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    Since its VB I think you should associate the eventhandler as:

    AddHandler SrcBaseOptions.Trace,AddressOf TraceEventHandler

    Let us know if you need more information.

     

  • 10-27-2009, 8:16 AM In reply to

    Re: MSDeploy API with asp.net 2.0

    Hello Moshaikh,

    I tried the piece of code you sent me. But it is not working meaning it is not logging anything when the page is running. Where is it supposed to log?

    I am sure that I am doing something wrong. That's why I am providing my code below

    ----------------------------------------------------------------------------------------------------------------------------

    Imports System.Diagnostics
    Imports Microsoft.Web.Deployment
    Imports System.Xml
    Partial Class Deploy
        Inherits System.Web.UI.Page
        Dim strmode As String
        Dim strSitename As String
        Dim strSourceMetakey As String
        Dim strSourceServer As String
        Dim strDestMetaKey As String
        Dim strDestServer As String
        Dim strAppPoolName As String
        Dim strArgs As String
        Dim sourceAppPoolProvider As New DeploymentWellKnownProvider
        Dim DestinationAppPoolProvider As New DeploymentWellKnownProvider
        Dim sourceProvider As New DeploymentWellKnownProvider
        Dim destinationProvider As New DeploymentWellKnownProvider


        Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

            Try
               
                Dim sourceBaseOptions As New DeploymentBaseOptions()           
                AddHandler sourceBaseOptions.Trace, AddressOf TraceEventHandler
                sourceBaseOptions.TraceLevel = TraceLevel.Info

                Dim destinationBaseOptions As New DeploymentBaseOptions()
                Dim destinationSyncOptions As New DeploymentSyncOptions()
                destinationBaseOptions.ComputerName = strDestServer


                Dim availableRules As DeploymentRuleCollection = DeploymentSyncOptions.GetAvailableRules()
               

     For Each rule As DeploymentRule In availableRules
                    If rule.Name.Equals("DefaultDependencyCheck") Then
                        destinationSyncOptions.Rules.Remove("DefaultDependencyCheck")
                    End If
                    If rule.Name.Equals("default") Then
                        destinationSyncOptions.Rules.Remove("default")
                    End If

                Next
               
                For Each linkExtension As DeploymentLinkExtension In destinationBaseOptions.LinkExtensions
                    If (linkExtension.Name.Equals("AppPoolExtension", StringComparison.OrdinalIgnoreCase)) Then
                        linkExtension.Enabled = True
                        Exit For

                    End If
                Next
               
               
                If Trim(strAppPoolName) <> "" Then
                    sourceAppPoolProvider = DeploymentWellKnownProvider.AppPoolConfig
                    DestinationAppPoolProvider = DeploymentWellKnownProvider.AppPoolConfig
                   

    Using deploymentObject As DeploymentObject = DeploymentManager.CreateObject(sourceAppPoolProvider, strAppPoolName, sourceBaseOptions)
                       

     deploymentObject.SyncTo(DestinationAppPoolProvider, strAppPoolName, destinationBaseOptions, destinationSyncOptions)
                   

    End Using
                End If

                          
                sourceProvider = DeploymentWellKnownProvider.MetaKey
                destinationProvider = DeploymentWellKnownProvider.MetaKey

                Using deploymentObject As DeploymentObject = DeploymentManager.CreateObject(sourceProvider, strSourceMetakey, sourceBaseOptions)
                   

    deploymentObject.SyncTo(destinationProvider, strSourceMetakey, destinationBaseOptions, destinationSyncOptions)

                End Using
               
            Catch ex As Exception
                Response.Write(ex.Message)

            End Try
        End Sub


        Protected Sub TraceEventHandler(ByVal sender As Object, ByVal traceEvent As DeploymentTraceEventArgs)
            WriteEvent(traceEvent)
        End Sub

        Protected Sub WriteEvent(ByVal e As DeploymentTraceEventArgs)
            Dim traceLevel As TraceLevel = e.EventLevel
            Response.Write(e.Message)
            'Console.WriteLine(e.Message)
        End Sub

    ---------------------------------------------------------------------------------------------------------------------

    Can you please check this out and let me know what I am doing wrong here?

    Appreciate your taking time to help me out...

    Thanks a bunch!!!

     

  • 10-29-2009, 4:01 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    HI Moshaikh,

    I am waiting for a response from you? Would you please review my code and let me know what I am doing wrong?

  • 10-29-2009, 4:32 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    I tried the same code with two changes and I am getting it to give me the events:

    AddHandler sourceBaseOptions.Trace, AddressOf TraceEventHandler
                sourceBaseOptions.TraceLevel = TraceLevel.Verbose

    AddHandler destinationBaseOptions.Trace, AddressOf TraceEventHandler

    destinationBaseOptions.TraceLevel = TraceLevel.Verbose

    Make the tracelevel verbose and add the handler for the destinationbaseoptions.

    Let me know if you need more info.

     

  • 10-30-2009, 11:15 AM In reply to

    Re: MSDeploy API with asp.net 2.0

    I made this changes and it is working no doubt. Thank You!!! However, most of the information provided does not show the changes being made on the destination server. It is giving information like

    Source metaProperty (/lm/w3svc/7/ServerComment) replaced with changed attributes () due to rule EnvironmentVariableNormalize
    Source metaProperty (/lm/w3svc/7/ServerBindings) replaced with changed attributes () due to rule EnvironmentVariableNormalize
    Source metaProperty (/lm/w3svc/7/LogPluginClsid) replaced with changed attributes () due to rule EnvironmentVariableNormalize
    AddChild operation on metaProperty (/lm/w3svc/7/AuthFlags) skipped due to rule AboFilter
    AddChild operation on metaProperty (/lm/w3svc/7/NTAuthenticationProviders) skipped due to rule AboFilter

     

    However, I would like to have information like what is given below showing the change count

    Action: Updating filePath (d:\webs\Test5\wwwroot\web.config)
    Change count: 1 (I have been able to use achieve this using the msdeploy.exe through the process class but my actual intention is to take full use of the web deployment API's)

    Is this at all possible?
    I am really interested in using the web deployment dll to do all the work but it will be really unfortunate if I can't do so because of this

  • 10-30-2009, 1:34 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    When you use verbose tracing you will see the traces you want plus bunch of other trace messages you dont want. You can set this to Tracelevel.Info and it should give what you want.

    However, the change count is something you have to do. I have an example on my blog that does the counting as well as the formatting of output etc. You can look at it http://blogs.iis.net/moshaikh/archive/2009/09/25/msdeploy-xpath-and-xsl-part-ii-generating-formatted-output.aspx

    Let me know if you need more information.

  • 11-02-2009, 12:53 PM In reply to

    Re: MSDeploy API with asp.net 2.0

    I am trying to to incorporate the example that you have provided in my code but I am getting the following error

    Value of type 'Microsoft.Web.Deployment.DeploymentTraceEventArgs' cannot be converted to 'Microsoft.Web.Deployment.DeploymentObjectChangedEventArgs'.

    at the line

    Private Sub TraceEventHandler(ByVal sender As Object, ByVal e As DeploymentTraceEventArgs)

    'Dim ChangedEvent As DeploymentObjectChangedEventArgs = TryCast(e, DeploymentObjectChangedEventArgs)

    Any ideas??

Page 1 of 1 (10 items)
Microsoft Communities