[英]WinUI Registration Free WinRT Component
我遵循以下关于如何注册 UWP 注册免费 WinRT 组件的教程https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components /但我继续收到有关未注册组件的错误。
我首先创建一个 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>
编译解决方案时,组件的 Winmd 和 dll 被添加到 DUALITY.exe 文件夹中,但仅自动添加了 Component2 的 Winmd,所以我现在将其删除。 然后,我使用属性管理器实用程序将 Propertysheet.props 添加到应用程序项目中。 这禁用了添加引用的能力,但它仍然像已添加一样工作。 我的 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>
有人担心命名空间,我反复尝试了一些可能性。 我的 Appmanifest.xml 第 39 行出现错误:
“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。"
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>
此时,这是框架第一次尝试注册 dll。 这是我目前从文档中收集的所有信息。 可以看出 ActivatableClass 没有被添加,我很确定它应该被添加。
按照上面参考的教程,在WinUI 3.0下工作时,克服组件未注册的错误:
还包括 NuGet 包 Microsoft.VCRTForwarders.140,它做了一些管道。 将包应用到我的解决方案确实破坏了我的一个项目,我正在尝试修复它。
请按照所述继续使用 Propertysheet.props,注意从未合并的解决方案/x64 中的目标 winmd,并将 dll 复制到 exe 目录。 为每个项目添加一个。
链接器自动在主项目中包含 app.manifest。 不要遵循本教程并使用此文件来声明 activatableClasses。 编辑您的 Package.appmanifest 以将 dll 和 ativatableClass 添加为 in 或 out of proc 服务器。 使用 app.manifest 是一种快捷方式,您只能通过 Package.appmanifest 获得全部功能; 就像添加接口和 ProxyStub 一样。 需要 Package.appmanifest 声明,否则项目将无法解析 dll,并且如果在翻译单元中调用该类,则如果未声明 ActivatableClass,则编译将失败。 遵循架构https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/appx-package-manifest
由于包含 PropertySheet.props 和对 winmd 的引用,现在将添加并替换每次重建时引用的 winmd
接口不是 ActivatableClasses,而是在 Package.appmanifest 中的 ProxyStub 扩展下定义的
只有 Application.exe 项目应该有一个描述 Applications 依赖结构的 Package.appmanifest(似乎很明显)
如果您使用 Visual Studio Code 打开 Appmanifest.xml,请小心,VS Code 可能不会打开最新文件
在 UWP 与 WinUI 中如何做到这一点之间似乎存在脱节,无论多么小
我正在尝试使用 API 组件代理服务器进行后期绑定,以允许软件实例化完全由其接口和具有 GUID 的类工厂处理的类,或者使用经典的 COM 之类的东西。 我希望 WinRT 应用程序通过脚本或 xml 项目文件中给定的标识符来调用未知的第 3 方组件。 从我刚刚经历的过程来看,如果不求助于经典 COM,这似乎是不可能的。 我没问题。 该软件的基础可以在编译时由组件构建,而后端则在经典 COM 中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.