Created
December 8, 2019 13:09
-
-
Save baruchiro/6fe94269efdfb41260f594b05ce68745 to your computer and use it in GitHub Desktop.
Find all missing dll's from .deps.json and download them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# args: <Project directory> <App Name> | |
# Example: ~/source/myapp/bin/Release/netcoreapp2.1/publish myapp | |
import json | |
import sys | |
import os | |
import urllib.request | |
import zipfile | |
import tempfile | |
from shutil import copyfile | |
def getDllPathToNuget(depsJson): | |
linuxTargetKeyName = [t for t in depsJson['targets'] if 'linux-x64' in t][0] | |
runtimesNugetToDlls = {k: v['runtime'].keys() for k, v in depsJson['targets'][linuxTargetKeyName].items() if 'runtime' in v} | |
nativesNugetToDlls = {k: v['native'].keys() for k, v in depsJson['targets'][linuxTargetKeyName].items() if 'native' in v} | |
runtimesDllToNuget = {} | |
for nuget, runtimes in runtimesNugetToDlls.items(): | |
for runtime in runtimes: | |
runtimesDllToNuget[runtime] = nuget | |
for nuget, natives in nativesNugetToDlls.items(): | |
for native in natives: | |
runtimesDllToNuget[native] = nuget | |
return runtimesDllToNuget | |
def downloadNuget(nugetNameAndVersion): | |
nugetUrl = 'https://api.nuget.org/v3-flatcontainer/{package}/{version}/{package}.{version}.nupkg' | |
package, version = nugetNameAndVersion.split('/') | |
tmpDir = tempfile.gettempdir() | |
downloadFilePath = os.path.join(tmpDir, package + '.zip') | |
if not os.path.exists(downloadFilePath): | |
downloadUrl = nugetUrl.format(package=package, version=version) | |
print(f'Downloading {nugetNameAndVersion} from {downloadUrl}') | |
urllib.request.urlretrieve(downloadUrl, downloadFilePath) | |
unzipPath = os.path.join(tmpDir, package, version) | |
if not os.path.exists(unzipPath): | |
print(f'Unzipping {downloadFilePath} to {unzipPath}') | |
os.makedirs(unzipPath) | |
with zipfile.ZipFile(downloadFilePath) as zip: | |
zip.extractall(unzipPath) | |
return unzipPath | |
appFolder = sys.argv[1] | |
appName = sys.argv[2] | |
depsJsonPath = os.path.join(appFolder, appName + '.deps.json') | |
with open(depsJsonPath) as depsJson: | |
data = json.load(depsJson) | |
runtimesDllToNuget = getDllPathToNuget(data) | |
notExistDllsKeys = [] | |
for dll in runtimesDllToNuget.keys(): | |
dllName = os.path.basename(dll) | |
dllInExecDir = os.path.join(appFolder, dllName) | |
if not os.path.exists(dllInExecDir): | |
print(f'dll missing: {dllName}') | |
notExistDllsKeys.append(dll) | |
# print(notExistDllsKeys) | |
for dll in notExistDllsKeys: | |
nugetFilesPath = downloadNuget(runtimesDllToNuget[dll]) | |
dllExpectedPath = os.path.join(nugetFilesPath, dll) | |
dllDropPath = os.path.join(appFolder, os.path.basename(dll)) | |
print(f'Coping {dllExpectedPath} to {dllDropPath}') | |
copyfile(dllExpectedPath, dllDropPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dirty script to execute the following algorithm:
app.deps.json
file (by searching all nugets withruntime
ornative
DLL undertargets
).nuget.org
.nupck
toNugetName/Version
..deps.json
, related to theNugetName/Version
.