【问题标题】:Can't properly add .dll reference in VS Code无法在 VS Code 中正确添加 .dll 引用
【发布时间】:2023-03-22 16:59:01
【问题描述】:

我正在尝试在 VS Code 中将 shell32.dll 添加和使用到我的控制台项目中。我把它放到项目的根目录下,..\bin 和 ..\bin\Debug。我做了dotnet restore。我的 .csproj 文件中的代码是:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Shell32">
      <HintPath>shell32.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
    </Reference>
  </ItemGroup>
</Project>

但是当我将using Shell32; 添加到 Program.cs 时,它会给出错误“找不到类型或命名空间名称‘Shell32’”。请指教我做错了什么?

【问题讨论】:

    标签: c# visual-studio-code dll shell32


    【解决方案1】:

    您要添加Microsoft Shell Controls and Automation 的COM 引用,而不是引用实际的Shell32.dll。

    示例 XML:

    <ItemGroup>
        <COMReference Include="Shell32.dll">
          <Guid>50a7e9b0-70ef-11d1-b75a-00a0c90564fe</Guid>
          <VersionMajor>1</VersionMajor>
          <VersionMinor>0</VersionMinor>
          <WrapperTool>tlbimp</WrapperTool>
          <Lcid>0</Lcid>
          <Isolated>false</Isolated>
        </COMReference>
      </ItemGroup>
    

    【讨论】:

    • 我如何在 VS Code 中引用它?我只发现如何在 Visual Studio 中添加引用。
    • 复制粘贴我发布的 XML,而不是
    • 我这样做了,但仍然收到错误“尝试使用时找不到类型或命名空间名称'Shell32'。
    • 好的。我结束了使用 WindowsAPICodePack 来完成我的 shell 任务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2014-01-12
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多