[Python] How can i explicitly specify my runtime in pythonnet (.Net4.8 Framework SDK)? And how...

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to specify the .Net version explicitly. My requirement is: .Net Framework SDK 4.8

    How can I find out which runtime is being used?

    And how can I specify it explicitly?

    Running this code

    pythonnet.load()
    pythonnet.get_runtime_info()


    generated this output:

    Version: <undefined>
    Initialized: True
    Shut down: False
    Properties:
    domain =
    config_file = None


    Why is the Version undefined.

    My Requirements are .Net Framework SDK 4.8

    When i load this runtimeconfig.json

    {
    "runtimeOptions": {
    "tfm": "net4.8",
    "frameworks": [
    {
    "name": "Microsoft.NETCore.App",
    "version": "4.8"
    }
    ]
    }
    }


    import logging
    import os

    import pythonnet

    ROOT = os.path.abspath(os.path.dirname(__file__))
    logger = logging.getLogger(__name__)

    def initialize():
    pythonnet.load(
    "netfx",
    config_file=os.path.join(ROOT, "runtimeconfig.json"),
    )
    logger.info("------------>: %s", pythonnet.get_runtime_info())


    Output

    15:14:56,919 - dotnet:15 - INFO - ------------>: Runtime: .NET Framework
    =============
    Version: <undefined>
    Initialized: True
    Shut down: False
    Properties:
    domain =
    config_file = D:\xxx\yyy\src\sinplcproject\runtimeco…

    Continue reading...

Compartilhe esta Página