Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Need help customizing AppSource Deployment Project to Check for Existence of Pre-Requisite Solutions

Posted on by 1,579

I have a D365 App that I need to deploy via AppSource.

I have an AppSource Visual Studio Project.

I am currently at the step “Create an App Source Package for your software” as detailed here: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/create-package-app-appsource

I have the package and it deploys without error using the Package Deployment Tool.

My issue is that I need a little help changing how it deploys to make it more intelligent.

Specifically, the first 12 solutions listed in the ImportConfig.xml file are 3rd party pre-requisite components that I need to make sure are installed if they are not.

However, if the current or a newer version of each one is installed in the destination system, I need to make sure I don’t overwrite them or attempt to install them.

Therefore, I need a way to check the destination D365 instance to see if each component is installed and obtain the current version number if it is.

Then, if the solution does not exist in the destination system or if it does and version number is older than what I am providing, I need to have the deployer install or update the solution in the destination system.

Otherwise, if the version is the same or newer, I need to ensure the deployer simply moves on and checks the destination system for existence of the next pre-requisite solution, repeating the process above but with different version numbers.

A copy of my ImportConfig.xml file is provided in Exhibit 1A below.

My question is what exactly must I do, and where do I need to do it to perform this check and intelligent install process?

  1. Can this all be done in the ImportConfig.xml file?
  2. If yes, what specifically must I change in the ImportConfig.xml file in Exhibit 1A below to make it check and install as described above?
  3. If I need to do something in the PackageTemplate.cs file, what exactly must I do and where must I do it?

It would be great if someone could provide some code to help get me started.

I have provided a copy of my PackageTemplate.cs file in Exhibit 2A below.

EXHIBIT 1A


  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  

EXHIBIT 2A

using Microsoft.Uii.Common.Entities;
using Microsoft.Xrm.Tooling.PackageDeployment;
using Microsoft.Xrm.Tooling.PackageDeployment.CrmPackageExtentionBase;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACEServiceTechAppSource
{
    /// 
    /// Import package starter frame. 
    /// 
    [Export(typeof(IImportExtensions))]
    public class PackageTemplate : ImportExtension
    {
        /// 
        /// Called When the package is initialized. 
        /// 
        public override void InitializeCustomExtension()
        {
            // Do nothing.  

            // Validate the state of the runtime settings object.  
            if (RuntimeSettings != null)
            {
                PackageLog.Log(string.Format("Runtime Settings populated.  Count = {0}", RuntimeSettings.Count));
                foreach (var setting in RuntimeSettings)
                {
                    PackageLog.Log(string.Format("Key={0} | Value={1}", setting.Key, setting.Value.ToString()));
                }

                // Check to see if skip checks is present.  
                if (RuntimeSettings.ContainsKey("SkipChecks"))
                {
                    bool bSkipChecks = false;
                    if (bool.TryParse((string)RuntimeSettings["SkipChecks"], out bSkipChecks))
                        OverrideDataImportSafetyChecks = bSkipChecks;
                }
            }
            else
                PackageLog.Log("Runtime Settings not populated");
        }

        /// 
        /// Called Before Import Completes. 
        /// 
        /// 
        public override bool BeforeImportStage()
        {
            return true; // do nothing here. 
        }

        /// 
        /// Called for each UII record imported into the system
        /// This is UII Specific and is not generally used by Package Developers
        /// 
        /// App Record
        /// 
        public override ApplicationRecord BeforeApplicationRecordImport(ApplicationRecord app)
        {
            return app;  // do nothing here. 
        }

        /// 
        /// Called during a solution upgrade while both solutions are present in the target CRM instance. 
        /// This function can be used to provide a means to do data transformation or upgrade while a solution update is occurring. 
        /// 
        /// Name of the solution
        /// version number of the old solution
        /// Version number of the new solution
        /// Solution ID of the old solution
        /// Solution ID of the new solution
        public override void RunSolutionUpgradeMigrationStep(string solutionName, string oldVersion, string newVersion, Guid oldSolutionId, Guid newSolutionId)
        {

            base.RunSolutionUpgradeMigrationStep(solutionName, oldVersion, newVersion, oldSolutionId, newSolutionId);
        }

        /// 
        /// Called after Import completes. 
        /// 
        /// 
        public override bool AfterPrimaryImport()
        {
            return true; // Do nothing here/ 
        }

        #region Properties

        /// 
        /// Name of the Import Package to Use
        /// 
        /// if true, return plural version
        /// 
        public override string GetNameOfImport(bool plural)
        {
            return "ACE Service Tech App";
        }

        /// 
        /// Folder Name for the Package data. 
        /// 
        public override string GetImportPackageDataFolderName
        {
            get
            {
                // WARNING this value directly correlates to the folder name in the Solution Explorer where the ImportConfig.xml and sub content is located. 
                // Changing this name requires that you also change the correlating name in the Solution Explorer 
                return "ACEServiceTechApp";
            }
        }

        /// 
        /// Description of the package, used in the package selection UI
        /// 
        public override string GetImportPackageDescriptionText
        {
            get { return "Aloye Computer Enterprises - ACE Service Tech App for D365"; }
        }

        /// 
        /// Long name of the Import Package. 
        /// 
        public override string GetLongNameOfImport
        {
            get { return "Aloye Computer Enterprises - ACE Service Tech App for D365"; }
        }


        #endregion

    }
}

Any help, including some code to get me started would be greatly appreciated as I am diving into brand new territory here. 

  • Suggested answer
    ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Need help customizing AppSource Deployment Project to Check for Existence of Pre-Requisite Solutions

    This actually seems to be doing detection and not re-installing of the current version is present by default. 

    Screen-Shot-2020_2D00_12_2D00_27-at-6.29.35-PM.png

    This may be resolved based on the behavior I am observing in the screen shot. 

    Can anyone tell me what the expected behavior is if the installed component in the target/destination system is newer than the version being provided via AppSource Deployment?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans