错误NU1105无法找到项目信息 - 项目文件可能无效或缺少恢复所需的目标

Pao*_*o B 32 csproj visual-studio nuget nuget-package-restore visual-studio-2017

突然之间,我在解决方案中的3个项目中遇到以下错误:

Error NU1105 Unable to find project information for 'C:\code\example\src\libs\example.I18n\example.I18n.csproj'. 
The project file may be invalid or missing targets required for restore.
Run Code Online (Sandbox Code Playgroud)

只有项目中的内容发生了变化才会发生一些数据库更改,但过去从未遇到过任何问题.只有我更新到Visual Studio 2017 15.5的其他内容才会导致问题?

我尝试过 - 从源代码管理中删除和重新克隆解决方案.但仍然得到错误.我的同事机器没有问题所以必须是本地的东西.

其中一个.csproj文件的示例如果有帮助:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <AssemblyName>Example.I18n</AssemblyName>
    <PackageId>Example.I18n</PackageId>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="MessageFormat" Version="1.0.1" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

Ale*_*ois 54

升级到Visual Studio 2017的15.6版后,我也得到了同样的结果.

关闭VS并删除.vs文件夹为我修复了它.

  • 这对我有用,我不敢相信它有多愚蠢. (3认同)
  • 我的项目没有 .vs 文件夹,但关闭并重新打开 VS 有效。“你试过把它关掉再打开吗?” (2认同)
  • @emery.noel 这是一个隐藏文件夹。也许您还需要启用它的视图设置和扩展视图。 (2认同)
  • @TitoLeiva - 我可以看到隐藏的文件夹。但 vs 文件夹位于解决方案级别,而不是项目级别(我找错了地方) (2认同)

小智 38

我遇到了这个问题,我只是按照 VS 中的错误消息建议:
恢复解决方案。

所以我打开了命令行或包管理器控制台,chdir进入包含解决方案(.sln)文件的目录并刚刚发出

C:> dotnet 恢复 .\mySolution.sln

问题已解决。


小智 13

对我来说,磁盘上项目文件的外壳与解决方案文件中的外壳不匹配.

说我有一个LibraryA.csproj和的解决方案LibraryB.csproj,哪里LibraryB.csproj有参考LibraryA.csproj.在LibraryA.csproj解决方案文件中包含不正确的大小写将导致NU1105构建LibraryB.csproj:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryA", "LibraryA\Librarya.csproj", "{24DEBB3B-762A-491D-8B83-6D078C0B30C0}"
Run Code Online (Sandbox Code Playgroud)

升级到Visual Studio 2017的15.5版后,我开始看到这个问题.我没有遇到版本15.4.5的这个问题.


小智 9

打开 powershell 并运行恢复命令解决了我的问题。

dotnet restore Sample.sln
Run Code Online (Sandbox Code Playgroud)


Ada*_*dam 7

我在重复引用项目时遇到了这个错误。

<ProjectReference Include="..\ProjectA.csproj" />
<ProjectReference Include="..\ProjectA.csproj" />
Run Code Online (Sandbox Code Playgroud)

删除重复引用解决了错误。


Tys*_*ams 6

如果解决方案中未包含引用的项目,也会出现此错误消息.我今天遇到了这个问题,我在这里找到了解决方法.


Kev*_*don 5

对我有用的是

  1. 删除有问题的项目
  2. 构建解决方案
  3. 重新添加项目。