{"id":14986262,"url":"https://github.com/kant2002/winformscominterop","last_synced_at":"2025-04-04T22:08:21.602Z","repository":{"id":37968597,"uuid":"241438068","full_name":"kant2002/WinFormsComInterop","owner":"kant2002","description":"ComWrappers required to run NativeAOT and WinForms","archived":false,"fork":false,"pushed_at":"2023-09-29T09:24:10.000Z","size":718,"stargazers_count":189,"open_issues_count":27,"forks_count":26,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-04-27T06:21:22.040Z","etag":null,"topics":["aot","corert","csharp-sourcegenerator","nativeaot","winforms"],"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/kant2002.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.TXT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"andriikurdiumov","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-02-18T18:36:04.000Z","updated_at":"2024-05-28T02:26:23.091Z","dependencies_parsed_at":"2023-02-10T15:01:42.909Z","dependency_job_id":"9058797f-c2d1-4791-a213-3f472bafb97f","html_url":"https://github.com/kant2002/WinFormsComInterop","commit_stats":{"total_commits":220,"total_committers":2,"mean_commits":110.0,"dds":"0.013636363636363669","last_synced_commit":"b0bc9cfbc2608be20abbb15198ab8fe7d8ef0f5e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FWinFormsComInterop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FWinFormsComInterop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FWinFormsComInterop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FWinFormsComInterop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kant2002","download_url":"https://codeload.github.com/kant2002/WinFormsComInterop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256115,"owners_count":20909240,"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":["aot","corert","csharp-sourcegenerator","nativeaot","winforms"],"created_at":"2024-09-24T14:12:36.667Z","updated_at":"2025-04-04T22:08:21.586Z","avatar_url":"https://github.com/kant2002.png","language":"C#","readme":"ComWrappers required to run NativeAOT and WinForms\n=====================================================\n\nThis repository has ComWrappers implementation for WinForms.\nIn additional to that, it allow use WinForms and NativeAOT and R2R with trimming together.\n\n## Getting started\n\nJust add `WinFormsComInterop` to your project.\n```\ndotnet add package WinFormsComInterop\n```\n\nThen to your Program.cs add following line\n```\nComWrappers.RegisterForMarshalling(WinFormsComInterop.WinFormsComWrappers.Instance);\n```\n\nAnd modify project file to enable NativeAOT\n```\n\u003cPublishAot\u003etrue\u003c/PublishAot\u003e\n\u003c_SuppressWinFormsTrimError\u003etrue\u003c/_SuppressWinFormsTrimError\u003e\n```\n\nIf you application will works with this ComWrappers implementation, then most likely it would work with NativeAOT.\n\nIf you are using WebView2 using `Microsoft.Web.WebView2.Core` package, then use \n```\nComWrappers.RegisterForMarshalling(WinFormsComInterop.WebView2.WebView2ComWrapper.Instance);\n```\n\nNote, that it does not working for *new* WebView2 as of .NET 8, please file and issue if you need it, I'll prioritize.\n\nAlso \n1. Add `\u003cPackageReference Include=\"Microsoft.Web.WebView2\" Version=\"1.0.1462.37\" /\u003e` as depedency. This library would work only starting from this version of WebView2 package.\n2. Add RD.xml file from https://github.com/kant2002/RdXmlLibrary/blob/main/Microsoft.AspNetCore.Components.Web.rd.xml to project \n3. Add `\u003cRdXmlFile Include=\"Microsoft.AspNetCore.Components.Web.rd.xml\" /\u003e` to project file\n4. Make sure that RootComponets are added to you app-specific rd.xml\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cDirectives\u003e\n  \u003cApplication\u003e\n    \u003cAssembly Name=\"YourAppAssembly\" Dynamic=\"Required All\"\u003e\n      \u003cType Name=\"YourAppAssembly.YourRootComponent\" Dynamic=\"Required All\" /\u003e\n    \u003c/Assembly\u003e\n  \u003c/Application\u003e\n\u003c/Directives\u003e\n```\n\n## Testing technology\n\nTest that normal CoreCLR works\n```\ndotnet run --project samples\\SampleWindowsForms\\SampleWindowsForms.csproj\ndotnet run --project experiments\\WpfTestBed\\WpfTestBed.csproj\ndotnet run --project experiments\\WinUITestBed\\WinUITestBed\\WinUITestBed.csproj\ndotnet run --project experiments\\WinUIUWP\\WinUIUWP.csproj\n```\n\n## NativeAOT\nTest that NativeAOT works. \nRun commands in x64 developer tools.\n\n### WinForms\n```\ndotnet publish -r win-x64 samples\\SampleWindowsForms\\SampleWindowsForms.csproj\n\"samples\\SampleWindowsForms\\bin\\x64\\Debug\\net6.0-windows\\win-x64\\publish\\SampleWindowsForms.exe\"\n```\n\nBelow are experimental projects. They are need additional work.\n\n### WPF\n```\ndotnet publish -r win-x64 experiments\\WpfTestBed\\WpfTestBed.csproj -p:GenerateWPF=true\n```\n\n blocked by https://github.com/kant2002/WinFormsComInterop/issues/30\n\n ### WinUI\n```\ndotnet publish -r win10-x64 experiments\\WinUITestBed\\WinUITestBed\\WinUITestBed.csproj\n```\n\n### Classic UWP project\n```\ndotnet publish -r win-x64 experiments\\WinUIUWP\\WinUIUWP.csproj\n```\n\ndoes not work due to this error \n```\nexperiments\\WinUIUWP\\WinUIUWP.csproj : error MSB4057: The target \"Restore\" does not exist in the project.\n```\n\n## For brave souls\n\nMostly notes for me, but maybe somebody would like to hack.\n\nBuild [NativeAOT](https://github.com/dotnet/runtimelab/tree/feature/NativeAOT).\n\nModify nuget.config\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cconfiguration\u003e\n  \u003cpackageSources\u003e\n    \u003c!--To inherit the global NuGet package sources remove the \u003cclear/\u003e line below --\u003e\n    \u003cclear /\u003e\n    \u003c!--Locally built version of NativeAOT --\u003e\n    \u003cadd key=\"ILC\" value=\"c:\\runtimelab\\artifacts\\packages\\Debug\\Shipping\\\" /\u003e\n    \u003c!--To use daily builds of runtime --\u003e\n    \u003cadd key=\"dotnet6\" value=\"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json\" /\u003e\n  \u003c/packageSources\u003e\n\u003c/configuration\u003e\n```\n\nRestore packages to local folder to not pollute global Nuget cache. You will build NativAOT a lot.\n```\ndotnet restore -r win-x64 --packages packages\n```\n\nThen publish applications using regular workflow described above.\n\n\n# Additional reading\n\nDesign of future stubs in Runtime\n- https://github.com/dotnet/runtimelab/blob/feature/DllImportGenerator/designs/Pipeline.md#stub-code-generation\n","funding_links":["https://ko-fi.com/andriikurdiumov"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkant2002%2Fwinformscominterop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkant2002%2Fwinformscominterop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkant2002%2Fwinformscominterop/lists"}