C# - The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
이상하군요, 분명히 프로젝트는 참조되어 있고,
...[생략]...
<ItemGroup>
<ProjectReference Include="..\TestLib.csproj">
<Project>{9c601566-1156-4d9f-a61e-15fd087992aa}</Project>
<Name>TestLib</Name>
</ProjectReference>
</ItemGroup>
...[생략]...
대상 프로젝트도 잘 빌드가 되는데, 그에 속한 타입을 쓰려면 다음과 같이 컴파일 오류가 발생합니다.
The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
이런 식의 오류가 발생하는 대표적인 시나리오가 하나 있습니다. 그것은, 대상 프로젝트(위의 경우 TestLib.csproj)의 "Target Framework"을 올린 경우입니다. (그래서 정상적으로 csproj에 ProjectReference 기록이 남아 있던 것입니다.)
즉, (위의 경우 TestLib.csproj) 대상 프로젝트는 Target Framework을 4.8로 했는데, 그것을 참조해서 쓰는 프로젝트의 경우 "4.7"이라면 저런 식으로 빌드 오류가 발생합니다.
그리고, 수많은 오류 속에 여러분들은 간과했겠지만 "Error List"의 중간에는 분명히 다음과 같은 경고 메시지가 있었을 것입니다.
Warning The primary reference "...[생략]...\TestLib\bin\Debug\TestLib.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.8" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.7".
따라서, 그것을 참조하는 프로젝트 스스로도 4.8 버전으로 Target Framework을 올려야 합니다.
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]