2

I am trying to find a way to generate the package.xml using metadata stored locally on my machine without using any org.

I have found a lot of alternatives when you want to generate a package.xml using as a reference a defined environment but no result when you already have the metadata folder.

Do you know if it is possible?

Thanks!

1 Answer 1

5

You could use the sfdx convert commands as follows.

Let's say your metadata API files are stored in a folder called mdapi.

In folder mdapi, add a package.xml file with one metadata type found in your files for e.g ApexClass. The package.xml is required for convert command and must exist in the folder even if it does not list all components:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
  <types>
    <members>*</members>
    <name>ApexClass</name>  
  </types>
  <version>47.0</version>
</Package>

Convert mdapi folder to source format:

sfdx force:mdapi:convert -r ./mdapi/ -d force-app

Then convert the newly created force-app source format repository again to metadata API to generate the package.xml based on the files found

sfdx force:source:convert -r ./force-app/ -d mdapi2

The mdapi2 folder will contain the package.xml file and the subfolders with the metadata components

2
  • I have tried to convert mdapi folder to source format without providing the package.xml inside the mdapi folder and I have received this error message " the path specified is not a directory or doesn’t contain a package.xml"
    – vt89
    Dec 6, 2019 at 12:17
  • 1
    I have edited my answer: in mdapi folder you need to specify a 'package.xml' file with one metadata type at least. This is required for the first sfdx convert command
    – Shamina
    Dec 6, 2019 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .