Skip to content

Instantly share code, notes, and snippets.

@IceLitty
Last active June 28, 2022 09:24
Show Gist options
  • Save IceLitty/90fea8dd0a1b3cdc6eb0dcda6d531bf4 to your computer and use it in GitHub Desktop.
Save IceLitty/90fea8dd0a1b3cdc6eb0dcda6d531bf4 to your computer and use it in GitHub Desktop.
Update Everything and WebSearch plugins for PowerToys v0.57.2

English

  1. PowerToys throws exception when close PowerToys Run, we can get log files location in %appdata%\..\Local\Microsoft\PowerToys\PowerToys Run\Logs\0.57.2.0\. Open PowerToys Run will active these broken plugins, log system will print detail in these file.
    [2022-04-21 19:49:00.7245] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Wox.Plugin\PluginPair.cs::154]
    -------------------------- Begin exception --------------------------
    Message: Couldn't get assembly types for Everything in C:\Program Files\PowerToys\modules\launcher\Plugins\Community.PowerToys.Run.Plugin.Everything\Community.PowerToys.Run.Plugin.Everything.dll. The plugin might be corrupted. Uninstall PowerToys, manually delete the install folder and reinstall.
    
    Exception full name  : System.Reflection.ReflectionTypeLoadException
    Exception message    : Unable to load one or more of the requested types.
    Could not load file or assembly 'Microsoft.PowerToys.Settings.UI.Lib, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。
    Exception stack trace:
       at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
       at System.Reflection.Assembly.GetTypes()
       at Wox.Plugin.PluginPair.CreatePluginInstance()
    Exception source     : System.Private.CoreLib
    Exception target site: System.RuntimeType[] GetTypes(System.Reflection.RuntimeModule)
    Exception HResult    : -2146232830
    -------------------------- End exception --------------------------
    ...
    [2022-04-21 19:49:01.8673] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Wox.Plugin\PluginPair.cs::204]
    -------------------------- Begin exception --------------------------
    Message: Fail to Init plugin: Web Search
    
    Exception full name  : System.IO.FileNotFoundException
    Exception message    : Could not load file or assembly 'ManagedCommon, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。
    Exception stack trace:
       at Top.Iseason.PTPlugins.WebSearch.Main.Init(PluginInitContext context)
       at Wox.Plugin.PluginPair.InitPlugin(IPublicAPI api)
    Exception source     : Top.Iseason.PTPlugins.WebSearch
    Exception target site: Void Init(Wox.Plugin.PluginInitContext)
    Exception HResult    : -2147024894
    -------------------------- End exception --------------------------
    
  2. Find problem is PowerToys core can not find dll by plugins needed, but the Microsoft.PowerToys.Settings.UI.Lib and ManagedCommon are core's lib by PowerToys Run, just because developers changed their namespace.
  3. Simply fix: First, download plugins source.
  4. Copy the libraries needed by the plugin from PowerToys install directory C:\Program Files\PowerToys\modules\launcher.
    • Everything:
      • PowerToys.Common.UI.dll
      • PowerToys.Interop.dll
      • PowerToys.ManagedCommon.dll
      • PowerToys.ManagedTelemetry.dll
      • PowerToys.Settings.UI.Lib.dll
      • System.IO.Abstractions.dll
      • Wox.Infrastructure.dll
      • Wox.Plugin.dll
    • WebSearch:
      • PowerToys.Common.UI.dll
      • PowerToys.ManagedCommon.dll
      • System.IO.Abstractions.dll
      • Wox.Infrastructure.dll
      • Wox.Plugin.dll
  5. Change project's file .csproj
    • Everything:
      • PropertyGroup -> TargetFramework -> change to netcoreapp6.0-windows because useWPF is true
      • Change ItemGroup tag with linked other parent project to these:
        <ItemGroup>
           <Reference Include="PowerToys.Common.UI">
             <HintPath>.lib/PowerToys.Common.UI.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.Interop">
             <HintPath>.lib/PowerToys.Interop.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedCommon">
             <HintPath>.lib/PowerToys.ManagedCommon.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedTelemetry">
             <HintPath>.lib/PowerToys.ManagedTelemetry.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.Settings.UI.Lib">
             <HintPath>.lib/PowerToys.Settings.UI.Lib.dll</HintPath>
           </Reference>
           <Reference Include="System.IO.Abstractions">
             <HintPath>.lib/System.IO.Abstractions.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Infrastructure">
             <HintPath>.lib/Wox.Infrastructure.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Plugin">
             <HintPath>.lib/Wox.Plugin.dll</HintPath>
           </Reference>
         </ItemGroup>
    • WebSearch:
      • PropertyGroup -> TargetFramework -> change to netcoreapp6.0-windows because UseWindowsForms is true
      • Change ItemGroup tag with linked other parent project to these:
        <ItemGroup>
           <Reference Include="PowerToys.Common.UI">
             <HintPath>.lib/PowerToys.Common.UI.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedCommon">
             <HintPath>.lib/PowerToys.ManagedCommon.dll</HintPath>
           </Reference>
           <Reference Include="System.IO.Abstractions">
             <HintPath>.lib/System.IO.Abstractions.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Infrastructure">
             <HintPath>.lib/Wox.Infrastructure.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Plugin">
             <HintPath>.lib/Wox.Plugin.dll</HintPath>
           </Reference>
         </ItemGroup>
      • Copy https://github.com/microsoft/PowerToys/tree/main/src/codeAnalysis in project source and remove ItemGroup tag with these Included files:
      <ItemGroup>
         <Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
           <Link>GlobalSuppressions.cs</Link>
         </Compile>
         <AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
           <Link>StyleCop.json</Link>
         </AdditionalFiles>
       </ItemGroup>
  6. Use dotnet sdk run dotnet clean and dotnet build to build dll and files.
  7. Copy bin/Debug/ files to PowerToys Run plugin directory to replace old plugin files. All done.

中文

  1. 根据%appdata%\..\Local\Microsoft\PowerToys\PowerToys Run\Logs\0.57.2.0\处的日志文件可以获得报错详情,本次处理的问题是由于开发者更换了核心库的命名空间导致的。
  2. 下载两个插件的源码
  3. 从PowerToys安装目录C:\Program Files\PowerToys\modules\launcher拷贝以下dll到源码目录中(建立一个文件夹用来放第三方库如lib).
    • Everything:
      • PowerToys.Common.UI.dll
      • PowerToys.Interop.dll
      • PowerToys.ManagedCommon.dll
      • PowerToys.ManagedTelemetry.dll
      • PowerToys.Settings.UI.Lib.dll
      • System.IO.Abstractions.dll
      • Wox.Infrastructure.dll
      • Wox.Plugin.dll
    • WebSearch:
      • PowerToys.Common.UI.dll
      • PowerToys.ManagedCommon.dll
      • System.IO.Abstractions.dll
      • Wox.Infrastructure.dll
      • Wox.Plugin.dll
  4. 修改.csproj项目文件
    • Everything:
      • PropertyGroup -> TargetFramework -> 改成 netcoreapp6.0-windows
      • 改变包含引用父项目结构的ItemGroup标签为以下内容:
        <ItemGroup>
           <Reference Include="PowerToys.Common.UI">
             <HintPath>.lib/PowerToys.Common.UI.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.Interop">
             <HintPath>.lib/PowerToys.Interop.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedCommon">
             <HintPath>.lib/PowerToys.ManagedCommon.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedTelemetry">
             <HintPath>.lib/PowerToys.ManagedTelemetry.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.Settings.UI.Lib">
             <HintPath>.lib/PowerToys.Settings.UI.Lib.dll</HintPath>
           </Reference>
           <Reference Include="System.IO.Abstractions">
             <HintPath>.lib/System.IO.Abstractions.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Infrastructure">
             <HintPath>.lib/Wox.Infrastructure.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Plugin">
             <HintPath>.lib/Wox.Plugin.dll</HintPath>
           </Reference>
         </ItemGroup>
    • WebSearch:
      • PropertyGroup -> TargetFramework -> 改成 netcoreapp6.0-windows
      • 改变包含引用父项目结构(ProjectReference)的ItemGroup标签为以下内容:
        <ItemGroup>
           <Reference Include="PowerToys.Common.UI">
             <HintPath>.lib/PowerToys.Common.UI.dll</HintPath>
           </Reference>
           <Reference Include="PowerToys.ManagedCommon">
             <HintPath>.lib/PowerToys.ManagedCommon.dll</HintPath>
           </Reference>
           <Reference Include="System.IO.Abstractions">
             <HintPath>.lib/System.IO.Abstractions.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Infrastructure">
             <HintPath>.lib/Wox.Infrastructure.dll</HintPath>
           </Reference>
           <Reference Include="Wox.Plugin">
             <HintPath>.lib/Wox.Plugin.dll</HintPath>
           </Reference>
         </ItemGroup>
      • 拷贝https://github.com/microsoft/PowerToys/tree/main/src/codeAnalysis这个目录到源码中,并移除这些额外添加的标签:
      <ItemGroup>
         <Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
           <Link>GlobalSuppressions.cs</Link>
         </Compile>
         <AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
           <Link>StyleCop.json</Link>
         </AdditionalFiles>
       </ItemGroup>
  5. 使用dotnet sdk 执行 dotnet cleandotnet build 来构建项目。
  6. 复制项目的 bin/Debug/ 内的文件至 PowerToys Run 插件目录替换掉旧的插件文件,即可正常使用。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment