Giter Club home page Giter Club logo

winformscominterop's Introduction

ComWrappers required to run NativeAOT and WinForms

This repository has ComWrappers implementation for WinForms. In additional to that, it allow use WinForms and NativeAOT and R2R with trimming together.

Getting started

Just add WinFormsComInterop to your project.

dotnet add package WinFormsComInterop

Then to your Program.cs add following line

ComWrappers.RegisterForMarshalling(WinFormsComInterop.WinFormsComWrappers.Instance);

And modify project file to enable NativeAOT

<PublishAot>true</PublishAot>
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>

If you application will works with this ComWrappers implementation, then most likely it would work with NativeAOT.

If you are using WebView2 using Microsoft.Web.WebView2.Core package, then use

ComWrappers.RegisterForMarshalling(WinFormsComInterop.WebView2.WebView2ComWrapper.Instance);

Also

  1. Add <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1462.37" /> as depedency. This library would work only starting from this version of WebView2 package.
  2. Add RD.xml file from https://github.com/kant2002/RdXmlLibrary/blob/main/Microsoft.AspNetCore.Components.Web.rd.xml to project
  3. Add <RdXmlFile Include="Microsoft.AspNetCore.Components.Web.rd.xml" /> to project file
  4. Make sure that RootComponets are added to you app-specific rd.xml
<?xml version="1.0" encoding="utf-8" ?>
<Directives>
  <Application>
    <Assembly Name="YourAppAssembly" Dynamic="Required All">
      <Type Name="YourAppAssembly.YourRootComponent" Dynamic="Required All" />
    </Assembly>
  </Application>
</Directives>

Testing technology

Test that normal CoreCLR works

dotnet run --project samples\SampleWindowsForms\SampleWindowsForms.csproj
dotnet run --project experiments\WpfTestBed\WpfTestBed.csproj
dotnet run --project experiments\WinUITestBed\WinUITestBed\WinUITestBed.csproj
dotnet run --project experiments\WinUIUWP\WinUIUWP.csproj

NativeAOT

Test that NativeAOT works. Run commands in x64 developer tools.

WinForms

dotnet publish -r win-x64 samples\SampleWindowsForms\SampleWindowsForms.csproj
"samples\SampleWindowsForms\bin\x64\Debug\net6.0-windows\win-x64\publish\SampleWindowsForms.exe"

Below are experimental projects. They are need additional work.

WPF

dotnet publish -r win-x64 experiments\WpfTestBed\WpfTestBed.csproj -p:GenerateWPF=true

blocked by kant2002#30

WinUI

dotnet publish -r win10-x64 experiments\WinUITestBed\WinUITestBed\WinUITestBed.csproj

Classic UWP project

dotnet publish -r win-x64 experiments\WinUIUWP\WinUIUWP.csproj

does not working due to this error

experiments\WinUIUWP\WinUIUWP.csproj : error MSB4057: The target "Restore" does not exist in the project.

For brave souls

Mostly notes for me, but maybe somebody would like to hack.

Build NativeAOT.

Modify nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <!--Locally built version of NativeAOT -->
    <add key="ILC" value="c:\runtimelab\artifacts\packages\Debug\Shipping\" />
    <!--To use daily builds of runtime -->
    <add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
  </packageSources>
</configuration>

Restore packages to local folder to not pollute global Nuget cache. You will build NativAOT a lot.

dotnet restore -r win-x64 --packages packages

Then publish applications using regular workflow described above.

Additional reading

Design of future stubs in Runtime

winformscominterop's People

Contributors

fornever avatar kant2002 avatar wjk avatar

Watchers

 avatar

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.