I'm creating an installer for a program that has a couple of run-time dll dependencies. These dependencies are available as NuGet packages. I was wondering if I could somehow specify the list of NuGet packages to Inno Setup, such that it will download the packages and bundles the corresponding dll's in my installer?
If that is not possible, what is the intended way to bundle such run-time only dll's from a NuGet package in an installer?
You can use Inno Setup preprocessor to run nuget.exe
to download a package and generate [Files]
section entries based on the downloaded contents.
For example the following defines NuGetPackage
preprocessor macro that collects all files in lib\net45
folder of the downloaded package:
#pragma parseroption -p-
#define ProcessFile(Source, FindResult, FindHandle) \
FindResult \
? \
Local[0] = FindGetFileName(FindHandle), \
Local[1] = Source + "\\" + Local[0], \
"Source: \"" + Local[1] + "\"; DestDir: \"{app}\"\n" + \
ProcessFile(Source, FindNext(FindHandle), FindHandle) \
: \
""
#define NuGetPackage(Name) \
Exec("nuget.exe", "install " + Name, SourcePath, , SW_HIDE), \
Local[0] = FindFirst(AddBackslash(SourcePath) + Name + "*", faDirectory), \
Local[0] \
? \
Local[1] = FindGetFileName(Local[0]), \
Local[2] = AddBackslash(SourcePath) + Local[1], \
Local[3] = Local[2] + "\\lib\\net45", \
Local[4] = FindFirst(Local[3] + "\\*", 0), \
ProcessFile(Local[3], Local[4], Local[4]), \
: \
""
#pragma parseroption -p+
You can use it like:
[Files]
#emit NuGetPackage("NUnit")
#emit NuGetPackage("EntityFramework")
To get:
[Files]
Source: "C:\source\path\NUnit.3.8.1\lib\net45\nunit.framework.dll"; DestDir: "{app}"
Source: "C:\source\path\NUnit.3.8.1\lib\net45\nunit.framework.xml"; DestDir: "{app}"
Source: "C:\source\path\EntityFramework.6.1.3\lib\net45\EntityFramework.dll"; DestDir: "{app}"
Source: "C:\source\path\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll"; DestDir: "{app}"
Source: "C:\source\path\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.xml"; DestDir: "{app}"
Source: "C:\source\path\EntityFramework.6.1.3\lib\net45\EntityFramework.xml"; DestDir: "{app}"