Comments (6)
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
- 6.0.11
- Microsoft.NETCore.App
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.
Related issues and PRs:
dotnet/runtime#35465
dotnet/runtime#39167
dotnet/runtime#36990
from clr-loader.
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.
@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.
Why is this only a "workaround"? What are the limitations/risks of doing this?
from clr-loader.
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)
- Add a `.info` attribute to runtimes and drop the wrappers where possible
- Allow initialisation of `coreclr` without a preexisting runtime config
- dotnet_root detection broke in ubuntu 22.04 HOT 1
- COR_E_INVALIDOPERATION when running release branch HOT 7
- get_coreclr throws exception "TypeError: get_coreclr() takes 0 positional arguments but 1 was given" in version 0.2.3. Works in version 0.1.7 HOT 2
- Cannot find dotnet root on x64 darwin
- clr_loader.ffi.load_hostfxr might not load the latest version of hostfxr HOT 4
- Could not find a suitable hostfxr library HOT 13
- RuntimeInfo.version '<undefined>' HOT 2
- Tests fail to run if a newer runtime than 6.0 is installed
- RuntimeError: cannot call null pointer pointer from cdata 'int(*)(void *, int)'
- The __version__ attribute is not defined HOT 3
- " initializer for ctype 'char *' must be a bytes or list or tuple, not str" error
- Error loading clr into non-root domain HOT 2
- Suggestion: manage base directory when creating non-root domain
- Suggestion: ability to add binary folders to app domain HOT 1
- Missing TargetFrameworkName from AppDomain.SetupInformation
- clr-loader failed to load dll if the assembly path contain Chinese HOT 1
- Cannot set parameters for .net core start. AppContext.BaseDirectory cannot be set.
- Deadlock calling pythonnet.set_runtime twice HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clr-loader.