简体   繁体   English

Visual Studio 不加载项目引用

[英]Visual Studio doesn't load project references

I have a Visual Studio (Community 2013) solution with many c# projects on my pc and I've just upgraded to Windows 10 from 7. The project uses .Net Framework 4.0 Client Profile.我有一个 Visual Studio (Community 2013) 解决方案,我的电脑上有许多 c# 项目,我刚刚从 7 升级到 Windows 10。该项目使用 .Net Framework 4.0 Client Profile。 On win7 everything worked fine, but now one of the projects doesn't seems to load references.在 win7 上一切正常,但现在其中一个项目似乎没有加载引用。 There are yellow triangles near the referenced items, what are not items referenced from the same solution (so system and references downloaded by NuGet not loaded).引用项附近有黄色三角形,哪些不是从同一解决方案引用的项(因此系统和 NuGet 下载的引用未加载)。

参考...

The Resources is another project in the solution, the others not.资源是解决方案中的另一个项目,其他项目不是。 When I open the properties tab for a system reference, the Path field is empty, and so the Resolved field is False ...当我打开系统引用的属性选项卡时, Path字段为空,因此Resolved字段为False ...

空路径

Besides, in the .csproj file everything seems to be ok, there are <HintPath> nodes where needed, with relative (or absolute, if the reference is on another drive), and correct, existing paths.此外,在 .csproj 文件中似乎一切正常,需要的地方有<HintPath>节点,具有相对(或绝对,如果引用在另一个驱动器上)和正确的现有路径。
Another weird thing: in the Object Browser all of the references are (seemingly) loaded:另一件奇怪的事情:在对象浏览器中,所有引用都(似乎)加载了:

对象浏览器似乎没问题

So, what should I do:所以我该怎么做:

  • re-create the project file (by creating new project and add all files and references again);重新创建项目文件(通过创建新项目并再次添加所有文件和引用);
  • change something in the configuration of the project;更改项目配置中的某些内容;
  • use a newer version of .Net;使用较新版本的 .Net;
  • change something in the configuration of VS;更改 VS 的配置;
  • use another VS (eg. Community 2015) or reinstall the current one?使用另一个 VS(例如 Community 2015)还是重新安装当前的?

I also had this problem and it took me some time to figure it out.我也遇到了这个问题,我花了一些时间才弄明白。 The problem is that NuGet changed how the packages are restored.问题是 NuGet 改变了包的恢复方式。 The "old way" needed the ".nuget" folder with 3 files (nuget.config, nuget.exe, nuget.targets) and some settings in the project file like: “旧方法”需要包含 3 个文件(nuget.config、nuget.exe、nuget.targets)的“.nuget”文件夹和项目文件中的一些设置,例如:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

This caused the project to be broken.这导致项目被破坏。

To fix this , copy the missing directory to the project (get it with an older version of Visual Studio/NuGet or from a co-worker who has it) or just simply delete the aforementioned part from the project file.要解决此问题,请将丢失的目录复制到项目(使用旧版本的 Visual Studio/NuGet 或从拥有它的同事那里获取),或者只是简单地从项目文件中删除上述部分。

For best results, also remove:为获得最佳效果,还请删除:

<RestorePackages>true</RestorePackages> 

and

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

from the project file!从项目文件!


Find more on the subject here:在此处找到有关该主题的更多信息:

http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

https://docs.microsoft.com/en-us/visualstudio/ide/troubleshooting-broken-references https://docs.microsoft.com/en-us/visualstudio/ide/troubleshooting-broken-references

The main problem is the FRAMEWORK reference.主要问题是 FRAMEWORK 参考。

Load your project into VS and change it in your PROJECT PROPERTIES page (TARGET FRAMEWORK), upgrading to .NET 4.x (not client) or .NET 4.5将您的项目加载到 VS 并在您的项目属性页面(目标框架)中更改它,升级到 .NET 4.x(不是客户端)或 .NET 4.5

Make sure both projects are targeting same framework version.确保两个项目都针对相同的框架版本。 For ex:one with the target framework .Net Framework 4.5.1 will not work with 4.5例如:目标框架 .Net Framework 4.5.1 不适用于 4.5

If you are using "TFS", or any other versioning system this way I have solved the issue:如果您以这种方式使用“TFS”或任何其他版本控制系统,我已经解决了这个问题:

Compare the solution file with latest.将解决方案文件与最新版本进行比较。 I did this and realized visual studio has added a lot configurations itself for x86 and that caused the issue even I try to get a build with x64.我这样做了,并意识到 Visual Studio 本身为 x86 添加了很多配置,即使我尝试使用 x64 进行构建,这也会导致问题。 Checking out file then undoing the changes did the trick.签出文件然后撤消更改就可以了。

I got this issue in VS-2015(project was not loading references) when I moved the project to another folder.当我将项目移动到另一个文件夹时,我在 VS-2015(项目没有加载引用)中遇到了这个问题。 And the name of the new folder was big, I shortened the name, and reloaded project then it started working.新文件夹的名称很大,我缩短了名称,然后重新加载项目然后它开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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