nugetinstallationinno-setupnuget-package

Find a directory using wildcard in Inno Setup


I'm trying to get all the files in a directory recursively while using wildcard within the name of the directory in Inno Setup script.

I have came across examples for filename but none for a directory search.

Use Case: Basically, we have moved to using NuGet packages for our internal development projects. So each project makes a NuGet package which can be consumed by other project and/or developer.

Part of this we wish to use the Inno Setup to use the dlls and/or files from a NuGet package.

For example, we need to find the package folder matching "../packages/PackagesA.../", e.g. "PackageA v1.2.0".

Came across this How to bundle run-time-only dependencies from NuGet packages in Inno Setup installer?, which is almost exactly I want but it seems the code doesn't work in my Inno Script.

Any help or suggestion as how to approach this?


Solution

  • You can define an Inno Setup preprocessor function that will resolve the directory file mask. Use FindFirst function for that:

    #define FindFolder(Path) \
        Local[0] = FindFirst(Path, faDirectory), \
        Local[0] ? \
            AddBackslash(ExtractFileDir(Path)) + FindGetFileName(Local[0]) : Path
    
    [Files]
    Source: "{#FindFolder("..\packages\PackagesA*")}\*.*"; DestDir: "{app}"; \
        flags: recursesubdirs  
    

    If you add SaveToFile call to the end of the script:

    #expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")
    

    ... you will see that the above code resolves to:

    [Files]
    Source: "..\packages\PackageA1.2.0\*.*"; DestDir: "{app}"; flags: recursesubdirs  
    

    If no such folder is found, the code resolves to:

    [Files]
    Source: "..\packages\PackageA*\*.*"; DestDir: "{app}"; flags: recursesubdirs  
    

    ... and the compiler will then fail with "No files found matching ...".