【问题标题】:Project works in Visual Studio. But vscode + Omnisharp fails with "You need to specify platform (x86, Win32 or x64)" for Nuget pkg: ScreenRecorderLib项目在 Visual Studio 中运行。但是 vscode + Omnisharp 失败,“您需要为 Nuget pkg 指定平台(x86、Win32 或 x64)”:ScreenRecorderLib
【发布时间】:2021-12-13 14:07:31
【问题描述】:

我有在 Visual Studio 中创建的 C# .Net Framework Winforms 项目。在 Visual Studio 中,一切都很好,它可以编译、调试、运行等。

但是当我尝试使用 Omnisharp 扩展在 vscode 中处理我的项目时,Omnisharp 甚至无法解析我的项目,它失败并出现错误:

...\packages\ScreenRecorderLib.3.1.2\build\ScreenRecorderLib.targets(6,5): Error: ScreenRecorderLib does not work correctly on 'AnyCPU' platform. You need to specify platform (x86, Win32 or x64).

  • 问题 #1:为什么这只是 vscode/Omnisharp 的问题,而 Visual Studio 中一切正常?

  • 问题 #2:我该如何解决?

我已经尝试在 Visual Studio 中查看项目属性,并且我已经将所有内容都设置为 x64,只要我能找到我的项目(请参见下面的屏幕截图)。虽然错误与我正在使用的 Nuget 包有关:ScreenRecorderLib... 那么这甚至可以在我自己的项目文件中修复吗?

【问题讨论】:

    标签: c# .net visual-studio-code omnisharp


    【解决方案1】:

    这里也是同样的问题。我通过编辑 C:\Users\\.nuget\packages\screenrecorderlib\3.1.2\build 文件夹下的 ScreenRecorderLib.targets 文件来避免这个问题。

    我的最终文件是这样的:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
    
      <Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
      <ItemGroup>
        <Reference Include="ScreenRecorderLib">
          <HintPath>$(MSBuildThisFileDirectory)x64\ScreenRecorderLib.dll</HintPath>
        </Reference>
      </ItemGroup>
      </Target>
    </Project>
    

    您可能会注意到,我以某种方式“强制”使用 x64 dll,因为它是我所需要的。我不能将此视为问题的解决方案,但至少我可以跳过此问题并继续。

    【讨论】:

      猜你喜欢
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      相关资源
      最近更新 更多