[英]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.