首页 > 解决方案 > C# 类型在命名空间中不存在/名称在当前上下文中不存在

问题描述

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

标签: c#visual-studio-code

解决方案


在 Visual Studio Code 中,打开 your.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>

推荐阅读