15

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?

smparedes
  • 391
  • 2
  • 9
  • 1
    @mickfold "How do I fix this error?" is a very valid question given that this is the first result when searching for this error online. It relates to developing software, and I'm not sure how relevant more specific details could be about the use case. I think it's a great question for SO! – Nick Bull Feb 10 '19 at 11:56

1 Answers1

24

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" />
smparedes
  • 391
  • 2
  • 9