smparedes
smparedes

Reputation: 411

The file could not be added to the project. This file is within the project directory tree error

Whenever I try to add a file to my Visual Studio project, I get the following warning:

The file [filename] could not be added to the project. This file is within the project directory tree

How do I fix this error?

Upvotes: 16

Views: 6831

Answers (1)

smparedes
smparedes

Reputation: 411

Go in to your Windows File Explorer and navigate to the .csproj file and open it with Notepad (or advanced text editor like NotePad++)

You will notice two lines that have similar or duplicate Compile Include lines:

<Compile Include="..\ProjectDir\SubDir\MyClass.cs">
  <Link>"SubDir\MyClass.cs"</Link>
</Compile>

Remove the Above line and keep only the line similar to the one below:

<Compile Include="SubDir\MyClass.cs" />

Upvotes: 25

Related Questions