{"id":13429942,"url":"https://github.com/matiasinsaurralde/go-dotnet","last_synced_at":"2025-04-06T07:14:05.043Z","repository":{"id":57491910,"uuid":"64059587","full_name":"matiasinsaurralde/go-dotnet","owner":"matiasinsaurralde","description":"Go wrapper for the .NET Core Runtime.","archived":false,"fork":false,"pushed_at":"2018-05-24T12:04:33.000Z","size":1976,"stargazers_count":486,"open_issues_count":6,"forks_count":42,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-03-30T06:06:40.632Z","etag":null,"topics":["dotnet","dotnet-core","golang","wrapper"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matiasinsaurralde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-24T10:08:21.000Z","updated_at":"2025-03-08T23:55:22.000Z","dependencies_parsed_at":"2022-09-02T00:13:04.732Z","dependency_job_id":null,"html_url":"https://github.com/matiasinsaurralde/go-dotnet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matiasinsaurralde%2Fgo-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matiasinsaurralde%2Fgo-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matiasinsaurralde%2Fgo-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matiasinsaurralde%2Fgo-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matiasinsaurralde","download_url":"https://codeload.github.com/matiasinsaurralde/go-dotnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445680,"owners_count":20939961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","dotnet-core","golang","wrapper"],"created_at":"2024-07-31T02:00:48.240Z","updated_at":"2025-04-06T07:14:05.027Z","avatar_url":"https://github.com/matiasinsaurralde.png","language":"C++","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Build Automation"],"sub_categories":["Build Automation","自动部署"],"readme":"# go-dotnet\n\n[![GoDoc](https://godoc.org/github.com/matiasinsaurralde/go-dotnet?status.svg)](https://godoc.org/github.com/matiasinsaurralde/go-dotnet)\n[![MIT License][license-image]][license-url]\n[![Build status][travis-build-image]][travis-build-status]\n\nThis is a PoC Go wrapper for the .NET Core Runtime, this project uses ```cgo``` and has been tested under OSX. It covers two basic use cases provided by the [CLR Hosting API](https://blogs.msdn.microsoft.com/msdnforum/2010/07/09/use-clr4-hosting-api-to-invoke-net-assembly-from-native-c/):\n\n* Load and run an .exe, using its default entrypoint, just like [corerun](https://github.com/dotnet/coreclr/blob/master/src/coreclr/hosts/unixcorerun/corerun.cpp) and [coreconsole](https://github.com/dotnet/coreclr/blob/master/src/coreclr/hosts/unixcoreconsole/coreconsole.cpp) do, check ```ExecuteManagedAssembly```.\n\n* Load a .dll, setup [delegates](http://www.fancy-development.net/hosting-net-core-clr-in-your-own-process) and call them from your Go functions.\n\nI've tried calling both C# and VB.NET methods, of course you need to generate the assembly first, check below for more details!\n\n**Note: After some tweaks it seems to work fine under Linux! Remember to install the SDK first :)**\n\n![Capture][capture]\n\n\n## An example\n\n```go\npackage main\n\nimport (\n\t\"github.com/matiasinsaurralde/go-dotnet\"\n\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hi, I'll initialize the .NET runtime.\")\n\n\t/*\n\t\tIf you don't set the TRUSTED_PLATFORM_ASSEMBLIES, it will use the default tpaList value.\n\t\tAPP_PATHS \u0026 NATIVE_DLL_SEARCH_DIRECTORIES use the path of the current program,\n\t\tthis makes it easier to load an assembly, just put the DLL in the same folder as your Go binary!\n\t\tYou're free to override them to fit your needs.\n\t*/\n\n\tproperties := map[string]string{\n\t\t// \"TRUSTED_PLATFORM_ASSEMBLIES\": \"/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/mscorlib.ni.dll:/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Private.CoreLib.ni.dll\",\n\t\t// \"APP_PATHS\":                     \"/Users/matias/dev/dotnet/lib/HelloWorld\",\n\t\t// \"NATIVE_DLL_SEARCH_DIRECTORIES\": \"/Users/matias/dev/dotnet/lib/HelloWorld\",\n\t}\n\n\t/*\n\t\tCLRFilesAbsolutePath sets the SDK path.\n\t\tIn case you don't set this parameter, this package will try to find the SDK using a list of common paths.\n\t\tIt seems to find the right paths under Linux \u0026 OSX, feel free to override this setting (like the commented line).\n\t*/\n\n\truntime, err := dotnet.NewRuntime(dotnet.RuntimeParams{\n\t\tProperties:                  properties,\n\t\t// CLRFilesAbsolutePath: \"/usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0\"\n\t})\n\tdefer runtime.Shutdown()\n\n\tif err != nil {\n\t\tfmt.Println(\"Something bad happened! :(\")\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(\"Runtime loaded.\")\n\n\tSayHello := runtime.CreateDelegate(\"HelloWorld\", \"HelloWorld.HelloWorld\", \"Hello\")\n\n    // this will call HelloWorld.HelloWorld.Hello :)\n\tSayHello()\n}\n```\n\n## Preparing your code (C#)\n\nI've used ```dmcs``` (from Mono) to generate an assembly file, the original code was something like:\n\n```c#\nusing System;\n\nnamespace HelloWorld {\n\n\tpublic class HelloWorld {\n    \tpublic static void Hello() {\n      \t\tConsole.WriteLine(\"Hello from .NET\");\n    \t}\n\t}\n\n}\n```\n\nAnd the command:\n\n```\ndmcs -t:library HelloWorld.cs\n```\n\n## Preparing your code (VisualBasic)\n\nI did a quick test with [this program](https://github.com/matiasinsaurralde/go-dotnet/blob/master/examples/HelloWorld.vb), using the VB.NET compiler from Mono:\n\n```\nvbnc -t:library HelloWorld.vb\n```\n\nI'm not sure about the status of [Roslyn](https://github.com/dotnet/roslyn) but it could be interesting to try it.\n\n## Setup\n\nComing soon!\n\n## Ideas\n\n* Run some benchmarks.\n* Add/enhance ```net/http``` samples, like [this](https://github.com/matiasinsaurralde/go-dotnet/blob/master/examples/http.go).\n* Provide useful callbacks.\n* Support blittable types.\n* CSharpScript support.\n* Code generation tool (with `go generate`), a few notes [here](https://github.com/matiasinsaurralde/go-dotnet/blob/master/code_generation.md).\n* **Add tests.**\n\nI'm open to PRs, Go/.NET swag, suggestions, etc.\n\n## Additional resources\n\n* [Hosting .NET Core](https://github.com/dotnet/docs/blob/master/docs/core/tutorials/netcore-hosting.md)\n\nBuild Status\n------------\n\nLinux x64 / Go 1.9/1.10 / .NET Core 1.0/2.0 - OS X / Go 1.9/1.10 - .NET Core 1.0/2.0\n\n[![Linux and OS X build status][travis-build-image]][travis-build-status]\n\nWindows / Go 1.9 / .NET Core 2.x\n\n[![Windows build status][windows-build-image]][windows-build-status]\n\n## License\n\n[MIT](LICENSE)\n\n[license-url]: LICENSE\n\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat\n\n[capture]: capture.png\n\n[travis-build-image]: https://travis-ci.org/matiasinsaurralde/go-dotnet.svg?branch=master\n[travis-build-status]: https://travis-ci.org/matiasinsaurralde/go-dotnet\n\n[windows-build-image]: https://ci.appveyor.com/api/projects/status/wc6hi7h89c6f83it/branch/windows-support?svg=true\n[windows-build-status]: https://ci.appveyor.com/project/matiasinsaurralde/go-dotnet/branch/windows-support","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatiasinsaurralde%2Fgo-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatiasinsaurralde%2Fgo-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatiasinsaurralde%2Fgo-dotnet/lists"}