将.NETCore 3.1依赖dll放入additionalProbingPaths

发布时间:2022-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了将.NETCore 3.1依赖dll放入additionalProbingPaths脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

修改 .NET Core 3.1 项目 依赖dll加载路径

1. 修改runtimeconfig.json

添加runtimeconfig.template.json 依赖dll放入的文件夹名称

{
  "addITionalPRobingPaths": [
    "lib"
  ]
}

2.根据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

脚本宝典总结

以上是脚本宝典为你收集整理的将.NETCore 3.1依赖dll放入additionalProbingPaths全部内容,希望文章能够帮你解决将.NETCore 3.1依赖dll放入additionalProbingPaths所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。