【问题标题】:C# type does not exist in the namespace/name does not exist in the current contextC# 类型在命名空间中不存在/名称在当前上下文中不存在
【发布时间】:2019-07-24 17:58:57
【问题描述】:

我的代码开头有using System.Deployment.Application; 行。 Application 下有一条红色波浪线,将鼠标悬停在它上面会给我以下信息:

The type or namespace name 'Application' does not exist in the namespace 'System.Deployment' (are you missing an assembly reference?) (CS0234)

当我使用ApplicationDeployment 时,这当然会给我带来问题,上面写着The name 'ApplicationDeployment' does not exist in the current context (CS0103)

为什么 Visual Studio 告诉我 Application 不是 System.Deployment 的一部分?

【问题讨论】:

  • 您是否引用了包含该命名空间的程序集?
  • @DanielA.White 我不这么认为...这是项目中唯一引用 System.Deployment.Application 的文件
  • @DanielA.White 我只是尝试运行dotnet add package System.Deployment.dll 行,终端说该项目不支持通过添加包命令添加包引用

标签: c# visual-studio-code


【解决方案1】:

在 Visual Studio Code 中,打开您的 .csproj 文件。在此文件中,您可以添加对 System.Deployment 的程序集引用,它应该可以解决您的问题。

参考:

    <Reference Include="System.Deployment"/>

这将被添加到 .csproj 文件的 ItemGroup 部分中

<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Deployment"/>
</ItemGroup>

【讨论】:

  • 在哪里可以找到解决方案资源管理器?
  • 如果有帮助,我有 VS Code 版本 1.35.1
  • @katiedidkatie:尽管名称令人困惑,但“Visual Studio”和“Visual Studio Code”是完全不同的应用程序。我怀疑你想为你的帖子找到一个 VS Code 标签。
  • @katiedidkatie 就像 Jon 提到的,Visual Studio 和 Visual Studio Code 是两个截然不同的野兽。我假设您没有使用 Visual Studio Code。这可能会对您有所帮助:stackoverflow.com/questions/42000798/…
猜你喜欢
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-04
  • 1970-01-01
  • 2021-01-02
相关资源
最近更新 更多