Domanda

Attualmente sto lavorando al mio servizio di amministrazione remota SharePoint. 1 delle funzioni è installare / rimuovere / aggiornare la soluzione.

Poiché la documentazione è molto breve su MSDN, mi chiedo se il seguente è sufficiente:

if (actionToTake == "REPLACE")
        {
            SPSolution solution = GetSolutionByName(nicename);
            if (solution != null)
            {
                if (solution.DeployedWebApplications.Count > 0)
                {
                    StateHandler.WriteValueToRegistry("30");
                    solution.Upgrade(fullpath);

                    Thread.Sleep(100);


                    while (solution.JobExists)
                    {
                        Thread.Sleep(100);
                    }

                    solution.Provision();

                    while (solution.JobExists)
                    {
                        Thread.Sleep(100);
                    }
                    StateHandler.WriteValueToRegistry("100");
                }
            }
.

Il codice esegue solo una disposizione alla fine, nessun aggiornamento ().Lo stesso per la nuova installazione e rimuovere Mi chiedo se è richiesta anche una chiamata da aggiornare () o altre azioni. Grazie!

È stato utile?

Soluzione

dont quite understand what your doing in code! but in my codeplex project i have a method that deploys all wsp's to a given spwebapplication!

    private void executeSolution(bool add)
    {
        try
        {                        
            Collection<SPWebApplication> webapps = new Collection<SPWebApplication>();
            SPWebApplication webapp = SPWebApplication.Lookup(new Uri(url));
            webapps.Add(webapp);

            SPSolutionCollection spSC = SPFarm.Local.Solutions;
            foreach (SPSolution spSolution in spSC)
            {

                if (spSolution.ContainsWebApplicationResource)
                {
                    if (add == true)
                    {
                        //deploy
                        spSolution.Deploy(DateTime.Now, true, webapps, true);
                        //logging
                        txtLogging.Text += spSolution.DisplayName + " to " + url + Environment.NewLine;
                    }
                    else
                    {
                        foreach (SPWebApplication weba in spSolution.DeployedWebApplications)
                        {
                            if (weba.Name == webapps[0].Name)
                            {
                                //retract
                                spSolution.Retract(DateTime.Now, webapps);
                                //logging
                                txtdebug.Text += spSolution.DisplayName + " removed from " + url + Environment.NewLine;
                                break;
                            }
                        }

                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        this.btnDeploy.Enabled = true;
        MessageBox.Show("Done, Please give it time for all the webparts that have been deployed to deploy." + Environment.NewLine + "Depending on the ammount of webparts deployed will determin how long it will take." + Environment.NewLine + "You will notice your web app performe an iisreset for each deployed webpart");
    }

lol you need to change the code tho so that it doesnt loop though each and every wsp, rather it just uses the only one wsp!

to have the full code its on codeplex at:

http://deployretractallwsp.codeplex.com/SourceControl/latest#bulkDeploymentv2/bulkDeployment/bulkDeployment/frmBulkDeploy.cs

was done in a rush about a year ago but it does the job! also it was done for 2007 but should be the same for 2010, code adds and retracts to a spwebapplication

also not that:

Performing a Replacement upgrade programmatically is the same as programmatically retracting the old solution and then adding and deploying the new version. To perform an Update type of upgrade programmatically, your code calls one of the overloads of the SPSolution.Upgrade() method. For this method to run, a solution must be present in the solution store. It may or may not already be deployed.

If the solution is not deployed, call the SPSolution.Upgrade(String) method to update the solution in the solution store.

If the solution is deployed, call the SPSolution.Upgrade(String, DateTime) method to start the timer job for upgrade. In either case, a backup of the old version of the solution is created.

http://msdn.microsoft.com/en-us/library/aa543659(v=office.14).aspx

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top