runtimeconfig.json
添加runtimeconfig.template.json
依赖dll放入的文件夹名称
{ "additionalProbingPaths": [ "lib" ] }
deps.json
移动dll的位置使用python脚本
moveDeps.py
import json import os target_dir = "" target_dlls = [] def loadRuntimeConfigJson(): with open("runtimeconfig.template.json") as f: temp = json.load(f) global target_dir if type(temp["additionalProbingPaths"]) == list: target_dir = temp["additionalProbingPaths"][0] if type(temp["additionalProbingPaths"]) == str: target_dir = temp["additionalProbingPaths"] def loadDepJson(): dep_name = None for file in os.listdir(): if file.endswith(".deps.json"): dep_name = file dep={} if dep_name is not None: with open(dep_name) as f: dep = json.load(f) targets = dict(dict(dep["targets"]).popitem()[1]) libraries = dict(dict(dep["libraries"])) global target_dlls for k, v in targets.items(): if not v.get("compileOnly") and libraries[k].get("type") == "package": try: t = targets[k]["runtime"].popitem() target_path = os.path.join( os.path.join(target_dir, libraries[k]["path"]), t[0]) target_dlls.append((os.path.split(t[0])[-1], target_path)) except: pass def MoveDlls(): global target_dlls for i, j in target_dlls: dir = os.path.dirname(j) if not os.path.exists(dir): os.makedirs(dir) os.rename(i, j) if __name__ == '__main__': loadRuntimeConfigJson() loadDepJson() MoveDlls()
发布完成后将py文件放入发布后的文件夹使用python3 moveDeps.py
就会根据dep.json文件将配置移动到lib文件中
相关资料
https://stackoverflow.com/questions/48650348/additionalprobingpaths-not-respected-after-dotnet-publish