【问题标题】:Cannot resolve "An assembly specified in the application dependencies manifest was not found" error无法解决“未找到应用程序依赖项清单中指定的程序集”错误
【发布时间】:2020-07-24 05:04:42
【问题描述】:

我正在尝试将我的 C# 项目发布到可执行文件以便分发它。但是,我引用了“Interop.IWshRuntimeLibrary”,并且由于包含它,我的项目发布但随后在执行时崩溃:

An assembly specified in the application dependencies manifest was not found:
    package: 'Interop.IWshRuntimeLibrary', version: '1.0.0.0'
    path: 'Interop.IWshRuntimeLibrary.dll'

到目前为止我已经尝试过:

  • 将 Interop.IWshRuntimeLibrary 的 Copy Local 和 Embed Interlop Types 属性设置为 true/false 的每种组合。

  • 在 .csproj 文件中将以下标记设置为 true/false。

<PublishWithAspNetCoreTargetManifest>
  • 安装 System.Runtime.InteropServices NuGet 包。

我的 .csproj 文件目前如下所示:

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>Project</RootNamespace>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup>
    <COMReference Include="IWshRuntimeLibrary.dll">
      <Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>0</VersionMinor>
      <WrapperTool>tlbimp</WrapperTool>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
    </COMReference>
  </ItemGroup>

项目中的其他参考资料,例如 Newtonsoft 工作正常。我已经查阅了我可以在网络上找到的与此相关的每个线程。我最接近描述我的问题的另一个线程是Could not load file or assembly Interop.IWshRuntimeLibrary?,但我在那里也没有发现有用的信息。

理想情况下,我只想单击发布并发布到我桌面上的一个文件夹 - 最好是单个 .exe,但如果它可以工作,整个文件夹就可以了。我不知道我是否可能在某处遗漏了一步,因为我以前从未使用过发布功能。我不知道下一步该尝试什么。谢谢。

【问题讨论】:

    标签: c# visual-studio com publish


    【解决方案1】:

    您目前的发布情况如何?

    您应该能够运行带有标志的发布命令来告诉它作为单个文件发布:

    dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
    

    更多信息在这里:https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-core-3-0/

    但至于您的特定问题。当作为单个文件发布时(您可能已经在这样做),涉及到某种程度的 treeshaking 来尝试限制它发布的依赖项。在某些情况下,如果您正在引用使用反射或类似方法加载的库,则 ILLinker 不知道它实际上正在被引用和使用。

    要解决这个问题,您可以在您的 csproj 文件中添加以下内容:

    <ItemGroup>
      <TrimmerRootAssembly Include="Interop.IWshRuntimeLibrary" />
    </ItemGroup>
    

    然后像这样发布你的项目:

    dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
    

    更多关于 ILLinker 工作原理的信息在这里:https://dotnetcoretutorials.com/2019/06/27/the-publishtrimmed-flag-with-il-linker/

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 2019-10-14
      • 2018-07-31
      • 2018-01-04
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多