简体   繁体   English

WinUI 注册免费 WinRT 组件

[英]WinUI Registration Free WinRT Component

I followed the following tutorial on how to register a UWP registration free WinRT component https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/ but I continue to receive errors about the component not being registered.我遵循以下关于如何注册 UWP 注册免费 WinRT 组件的教程https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components /但我继续收到有关未注册组件的错误。

I begin by creating a Propertysheet.props sheet, like in the tutorial:我首先创建一个 Propertysheet.props 表,就像在教程中一样:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup />
  <ItemGroup />
    <ItemGroup>
        <Reference Include="C:\Users\User\Solution\x64\Debug\Component\Component.winmd">
            <IsWinmdFile>true</IsWinmdFile>
        </Reference>
        <ReferenceCopyLocationPaths Include="C:\Users\User\Solution\x64\Debug\Component\Component.dll">
            <IsWinmdFile>false</IsWinmdFile>
        </ReferenceCopyLocationPaths>
        <!--<Reference Include="C:\Users\User\Solution\x64\Debug\Component2\Component2.winmd">
            <IsWinmdFile>true</IsWinmdFile>
        </Reference>
        <ReferenceCopyLocationPaths Include="C:\Users\User\Solution\x64\Debug\Component2\Component2.dll">
            <IsWinmdFile>false</IsWinmdFile>
        </ReferenceCopyLocationPaths>-->
    </ItemGroup>
</Project>

When the solution is compiled, the Winmd and the dll for Component are added to the DUALITY.exe folder, but only the Winmd for Component2 has been auto added so I remmed it out for now.编译解决方案时,组件的 Winmd 和 dll 被添加到 DUALITY.exe 文件夹中,但仅自动添加了 Component2 的 Winmd,所以我现在将其删除。 I then add the Propertysheet.props to the Application project using the properties manager utility.然后,我使用属性管理器实用程序将 Propertysheet.props 添加到应用程序项目中。 This disabled the ability to add reference, but it still works as though it has been added.这禁用了添加引用的能力,但它仍然像已添加一样工作。 My app.manifest looks like this:我的 app.manifest 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity version="1.0.0.0" name="Application.app"/>

  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
    </windowsSettings>
  </application>
    
    
  <file name="Component.dll">
    <activatableClass
        name="Component.SubNamespace.Class"
        threadingModel="both"
        xmlns="urn:schemas-microsoft-com:winrt.v1" />
  </file>
  <!--<file name="Component2.dll">
    <activatableClass
        name="Component.PeregrineX12"
        threadingModel="both"
        xmlns="urn:schemas-microsoft-com:winrt.v1" />
  </file>-->
    
</assembly>

There were concerns about Namespace and I itterated through a few possibilities.有人担心命名空间,我反复尝试了一些可能性。 I get an error in my Appmanifest.xml at line 39:我的 Appmanifest.xml 第 39 行出现错误:

"DEP0700: Registration of the app failed. [0x80080204] error 0xC00CE012: App manifest validation error: The app manifest must be valid as per schema: Line 39, Column 8, Reason: Content for element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}InProcessServer' is incomplete according to the DTD/Schema. Expecting: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}ActivatableClass." “DEP0700:应用程序注册失败。[0x80080204] 错误 0xC00CE012:应用程序清单验证错误:应用程序清单必须根据架构有效:第 39 行,第 8 列,原因:元素的内容'{http://schemas.microsoft根据 DTD/Schema,.com/appx/manifest/foundation/windows10}InProcessServer' 不完整。期望:{http://schemas.microsoft.com/appx/manifest/foundation/windows10}ActivatableClass。"

and the Appmanifest.xml looks like this: Appmanifest.xml 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap build" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
  <Identity Name="837f0535-5d07-4290-983b-a49988c57b12" Publisher="CN=User" Version="1.0.0.0" ProcessorArchitecture="x64" />
  <Properties>
    <DisplayName>Application</DisplayName>
    <PublisherDisplayName>User</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.22000.0" MaxVersionTested="10.0.22000.0" />
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
    <PackageDependency Name="Microsoft.WindowsAppRuntime.1.1" MinVersion="1001.524.1918.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
    <PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.30704.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
    <PackageDependency Name="Microsoft.VCLibs.140.00.Debug.UWPDesktop" MinVersion="14.0.30704.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
  </Dependencies>
  <Resources>
    <Resource Language="EN-US" />
  </Resources>
  <Applications>
    <Application Id="App" Executable="Application.exe" EntryPoint="Windows.FullTrustApplication">
      <uap:VisualElements DisplayName="Application" Description="DUALITY" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
        <uap:SplashScreen Image="Assets\SplashScreen.png" />
      </uap:VisualElements>
    </Application>
  </Applications>
  <Capabilities>
    <rescap:Capability Name="runFullTrust" />
  </Capabilities>
  <Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>Component.dll</Path>
      </InProcessServer>
    </Extension>
  </Extensions>
  <build:Metadata>
    <build:Item Name="cl.exe" Version="19.31.31107.0" />
    <build:Item Name="OptimizingToolset" Value="None" />
    <build:Item Name="TargetRuntime" Value="Native" />
    <build:Item Name="Microsoft.UI.Xaml.Markup.Compiler.dll" Version="1.0.0.0" />
    <build:Item Name="Microsoft.UniversalCRT.Debug" Version="10.0.22000.0" />
    <build:Item Name="makepri.exe" Version="10.0.22621.1 (WinBuild.160101.0800)" />
  </build:Metadata>
</Package>

At this point, this was the first time an attempt was made by the framework to register the dll.此时,这是框架第一次尝试注册 dll。 This is all of the information I have collected from documentation, at this time.这是我目前从文档中收集的所有信息。 As can be seen ActivatableClass was not added and I'm pretty sure it should have been.可以看出 ActivatableClass 没有被添加,我很确定它应该被添加。

When following the tutorial refenced above, when working in WinUI 3.0, to overcome the error that the component is unregistered:按照上面参考的教程,在WinUI 3.0下工作时,克服组件未注册的错误:

  1. also include the NuGet package Microsoft.VCRTForwarders.140 which does some plumbing.还包括 NuGet 包 Microsoft.VCRTForwarders.140,它做了一些管道。 Applying the package to my solution did break one of my projects and I am trying to fix it.将包应用到我的解决方案确实破坏了我的一个项目,我正在尝试修复它。

  2. do proceed with Propertysheet.props as described, keeping note to target winmd's from solution/x64 not under merged, and to copy the dll's to the exe directory.请按照所述继续使用 Propertysheet.props,注意从未合并的解决方案/x64 中的目标 winmd,并将 dll 复制到 exe 目录。 add one to every project.为每个项目添加一个。

  3. linker automatically includes app.manifest in main project.链接器自动在主项目中包含 app.manifest。 do not follow this tutorial and use this file to declare activatableClasses.不要遵循本教程并使用此文件来声明 activatableClasses。 edit your Package.appmanifest to add the dll and the ativatableClass as an in or out of proc server instead.编辑您的 Package.appmanifest 以将 dll 和 ativatableClass 添加为 in 或 out of proc 服务器。 using app.manifest is a shortcut and you only gain full functionality through Package.appmanifest;使用 app.manifest 是一种快捷方式,您只能通过 Package.appmanifest 获得全部功能; like adding Interfaces and a ProxyStub.就像添加接口和 ProxyStub 一样。 Package.appmanifest declarations are required or the project won't resolve the dll and if the class is called in a translation unit, compilation will fail if the ActivatableClass hasn't been declared.需要 Package.appmanifest 声明,否则项目将无法解析 dll,并且如果在翻译单元中调用该类,则如果未声明 ActivatableClass,则编译将失败。 follow the schema https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/appx-package-manifest遵循架构https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/appx-package-manifest

  4. the winmd under reference will now be added and replaced every rebuild because of the PropertySheet.props inclusion and the reference to the winmd由于包含 PropertySheet.props 和对 winmd 的引用,现在将添加并替换每次重建时引用的 winmd

  5. Interfaces are not ActivatableClasses and are defined under a ProxyStub Extension in Package.appmanifest接口不是 ActivatableClasses,而是在 Package.appmanifest 中的 ProxyStub 扩展下定义的

  6. only the Application.exe project should have a Package.appmanifest that describes the Applications dependency structure (seems obvious)只有 Application.exe 项目应该有一个描述 Applications 依赖结构的 Package.appmanifest(似乎很明显)

  7. If you are opening Appmanifest.xml using Visual Studio Code, careful, VS Code might not be opening the newest file如果您使用 Visual Studio Code 打开 Appmanifest.xml,请小心,VS Code 可能不会打开最新文件

  8. there seems to be disconnect between how this is done in UWP vs WinUI however small在 UWP 与 WinUI 中如何做到这一点之间似乎存在脱节,无论多么小

I'm trying to late bind using an API component proxy-server to allow the software to instantiate classes handled entirely by their interfaces and class factories with GUID's, or using something classic COM like.我正在尝试使用 API 组件代理服务器进行后期绑定,以允许软件实例化完全由其接口和具有 GUID 的类工厂处理的类,或者使用经典的 COM 之类的东西。 I desire to have a WinRT App call an unknown 3rd party component by an identifier given to it in a script or xml project file.我希望 WinRT 应用程序通过脚本或 xml 项目文件中给定的标识符来调用未知的第 3 方组件。 From the process I just went through, this does not seem possible without resorting to classic COM.从我刚刚经历的过程来看,如果不求助于经典 COM,这似乎是不可能的。 I'm ok with that.我没问题。 The base of the software can be built from components at compile time, while the back end operates in classic COM.该软件的基础可以在编译时由组件构建,而后端则在经典 COM 中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM