Code Monkey home page Code Monkey logo

Comments (6)

vgibilmanno avatar vgibilmanno commented on September 20, 2024 2

I found a neat workaround to run .NET projects in a self-contained manner which could suffice for most people encountering this issue. What we need to do is to bring dotnet by ourselves.

Example:

  • my-dotnet-directory
    • libhostfxr.so
    • shared
      • Microsoft.NETCore.App
        • 6.0.11
          • ...files

Because we are bringing all dotnet libraries already, we don't need to build our project as self-contained. Normally building the project is enough. This is how I call it in pythonnet

import os
from pythonnet import load

dotnet_root = os.path.abspath('./my-dotnet-directory')
runtime_config = os.path.abspath('runtimeconfig.json')
load("coreclr", dotnet_root=dotnet_root, runtime_config=runtime_config)

import clr
import os

clr.AddReference(os.path.abspath('./my-project/my-project.dll'))

from MyProject import Program
program = Program()
program.ExecuteSync()

This way I'm able to run my application as 'self-contained'

runtimeconfig.json:

{"runtimeOptions": {"tfm": "net6.0", "framework": {"name": "Microsoft.NETCore.App", "version": "6.0.11"}}}

from clr-loader.

filmor avatar filmor commented on September 20, 2024

Related issues and PRs:

dotnet/runtime#35465
dotnet/runtime#39167
dotnet/runtime#36990

from clr-loader.

rishky-msft avatar rishky-msft commented on September 20, 2024

I found a neat workaround to run .NET projects in a self-contained manner which could suffice for most people encountering this issue. What we need to do is to bring dotnet by ourselves.

Example:

  • my-dotnet-directory

    • libhostfxr.so

    • shared

      • Microsoft.NETCore.App

        • 6.0.11

          • ...files

Because we are bringing all dotnet libraries already, we don't need to build our project as self-contained. Normally building the project is enough. This is how I call it in pythonnet

import os
from pythonnet import load

dotnet_root = os.path.abspath('./my-dotnet-directory')
runtime_config = os.path.abspath('runtimeconfig.json')
load("coreclr", dotnet_root=dotnet_root, runtime_config=runtime_config)

import clr
import os

clr.AddReference(os.path.abspath('./my-project/my-project.dll'))

from MyProject import Program
program = Program()
program.ExecuteSync()

This way I'm able to run my application as 'self-contained'

runtimeconfig.json:

{"runtimeOptions": {"tfm": "net6.0", "framework": {"name": "Microsoft.NETCore.App", "version": "6.0.11"}}}

@vgibilmanno Are you able to run this in linux? I am trying in Ubuntu

from clr-loader.

vgibilmanno avatar vgibilmanno commented on September 20, 2024

@rishky-msft I'm able to run this on Debian 11 and Windows 11. It should work on Ubuntu too since it is based on Debian

from clr-loader.

sherryyshi avatar sherryyshi commented on September 20, 2024

Why is this only a "workaround"? What are the limitations/risks of doing this?

from clr-loader.

adwenn avatar adwenn commented on September 20, 2024

I just wanted to add a note about this workaround that was working fine in the past but now it seemed to stop working on my macbook M1. I did the test with NET8. I was getting an error. It was complaining that it couldn't find the dotnet-root folder. So after some trail and error i noticed an issue with the folder structure. see the example below.
Example:

• my-dotnet-directory

	• libhostfxr.so

	• shared

		• shared

			• Microsoft.NETCore.App

				• 6.0.11

					...files

As you can see there is a 'shared' directory within the 'shared' directory in my case this works now.

The runtimeconfig.json is still the same:

{"runtimeOptions": {"tfm": "net8.0", "framework": {"name": "Microsoft.NETCore.App", "version": "8.0.1"}}}

If anyone has a better solution to this. Please let us know.

from clr-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.