该文件无法添加到项目中.此文件位于项目目录树错误中

smp*_*des 11 project csproj visual-studio

每当我尝试将文件添加到Visual Studio项目时,都会收到以下警告:

无法将文件[filename]添加到项目中.该文件位于项目目录树中

我该如何解决这个错误?

smp*_*des 19

进入Windows文件资源管理器并导航到.csproj文件并使用记事本(或NotePad ++等高级文本编辑器)打开它

您会注意到两行具有相似或重复的Compile Include行:

<Compile Include="..\ProjectDir\SubDir\MyClass.cs">
  <Link>"SubDir\MyClass.cs"</Link>
</Compile>
Run Code Online (Sandbox Code Playgroud)

删除Above行并仅保留与下面类似的行:

<Compile Include="SubDir\MyClass.cs" />
Run Code Online (Sandbox Code Playgroud)