Reputation: 82934
This is a weird one.
I have Visual Studio 2013 installed. If I create a new project, Visual Studio immediately complains that it cannot find any of the references:
The project does however compile and run correctly, even though there are warnings in the error list:
If I look at the properties of any of these references, their paths are empty. If I load an existing project, Visual Studio can find its references and doesn't complain, even though it is targeting the same version of the .Net framework as the broken project (I've even had them both in the same solution with the same behaviour).
How can I fix this, and what could have caused it? Any suggestions welcome, as it is baffling me.
Upvotes: 14
Views: 16831
Reputation: 2575
In a most cases you need:
Upvotes: 0
Reputation: 3
I had a similar issue with vs2015. It turns out a file was added twice to the .csproj
Deleting the duplicated line solved it
Upvotes: 0
Reputation: 1
I recently had this happen in VS 2017. I had done some refactoring on a project where the csproj file had moved, then cloned the repository onto a new machine. The csProj file had multiple locations for the .projects directory. For example:
<Import Project="packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props')" />
<Import Project=".\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('.\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project=".\packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props" Condition="Exists('.\packages\Microsoft.Net.Compilers.1.2.1\build\Microsoft.Net.Compilers.props')" />
There were additional relative path errors below in the Error tags as well.
I looked for any places where I had duplicated, incorrect package relative paths, and removed the incorrect ones.
This caused it to build for me.
Good luck out there! -Mezz
Upvotes: 0
Reputation: 2405
I had a problem with an existing project, and by creating a new one and comparing the csproj files I had to add missing import lines like those: one at the beginning of the project element and one at the end.
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
...
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Upvotes: 1
Reputation: 89
This happens to me from time to time and I always suspect VS corruption, but it always turns out to be user error. It typically happens when I add a new project to a solution and try to reference earlier projects in the newly added project. In this case and in general, you can only add a reference if it targets the same or earlier .NET Framework version. In my case, inconsistent target framework versions caused the project to not recognize references and not allow compilation. Double checking consistency or proper target framework versions solved this problem for me.
Upvotes: 2
Reputation: 598
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way. Another possibility is that the target .NET Framework version of the class library is higher than that of the project.
Upvotes: 4
Reputation: 82934
With thanks to icemanind, I have the answer.
I closed Visual Studio, deleted the following directories and everything is now working as normal again:
C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0
C:\Users\<username>\AppData\Roaming\Microsoft\VisualStudio\12.0
Upvotes: 6