简体   繁体   中英

Visual Studio 2012: Project cannot be referenced

We developed a large solution containing ~35 projects with VS 2010, now we are thinking about migrating to VS 2012 Ultimate. I converted the solution file to VS 2012 and generally, everything works fine.

But whenever I open the solution, I get some warnings on a certain project A in the solution: "The project X cannot be referenced" "The project Y cannot be referenced" ... where A has project-references to X and Y. When I build the solution, I get errors that the Metadata of each respective DLL could not be found.

When I look at the references in the solution explorer, they are marked with a yellow warning-symbol. As soon as I simply click on the reference, the warning goes away and the icon looks normal. Then I can build without errors!

The problem occurs each time I open the solution, the affected projects are always the same.

Did anyone else experience this odd behavior? Deleting and adding the project references again did not help...

Thank you in advance.

EDIT: I checked the csproj file of the referencing project and I wonder that all project reference GUIDs having the above problem are written lowercase, other projects are uppercased.

<ProjectReference Include="..\Presentation.Net\Presentation.Net.csproj">
  <Project>{04004c6b-76c8-4f2d-9fcf-5a866bb80fd4}</Project>
  <Name>CMS.Presentation.Net</Name>
</ProjectReference>

While within the solution the GUIDs are uppercased:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presentation.Net", "Presentation.Net\Presentation.Net.csproj", "{04004C6B-76C8-4F2D-9FCF-5A866BB80FD4}"

Any ideas?

VS 2012 dropped support for some of the older project types. Not all of the VS 2010 project types are supported in VS 2012. For instance, the MSI setup project types have been replaced by InstallShield LE project types. Check the compatibility list here and see if any of your failing project types are an issue.

This pointed me into the right direction. Visual Studio 2012 Randomly reporting: "The referenced component X could not be found"

At least the warnings go away. Have to check whether the metadata errors will occur again.

尝试清理项目/解决方案,然后构建它。

When I ran into this problem, it was due to differing versions of .NET between the projects. You need to make sure that the project you are trying to reference has a compatible .NET version with the current project.

For example if your target project is .NET 4.5.2 and the project you reference is on 4.6, you can get this error as the referenced project is using components that your current project cannot access.

To solve it, simply go to the target project's properties and select the correct compatible version of .NET. For all my projects in my solution I maintain the same .NET version for each of them, especially if they are referencing each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM