Paolo B
Paolo B

Reputation: 3364

Error NU1105 Unable to find project information - The project file may be invalid or missing targets required for restore

All of a sudden, I am getting the following errors for 3 projects in a solution:

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.

The only thing that has changed in the project is a couple of DB changes, but I never had any issues in the past. The only other thing is that I updated to Visual Studio 2017 15.5. Could that cause issues?

I have tried removing and recloning the solution from source control, but still getting errors. No problems on my colleagues' machines, so it must be something local.

Example of one of the .csproj files if this helps:

<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>

Upvotes: 98

Views: 106885

Answers (28)

Mohamed Shaqrani
Mohamed Shaqrani

Reputation: 41

This just could happend if you recently renamed something across the entire solution, as it could affect the .csproj file

Upvotes: 0

Alexandre Brisebois
Alexandre Brisebois

Reputation: 6743

I also got the same after upgrading to version 15.6 of Visual Studio 2017.

Closing VS and deleting the .vs folder fixed it for me.

Upvotes: 109

Alberto Trentadue
Alberto Trentadue

Reputation: 679

I had this problem and I just followed what the error message recommends inside VS:
To restore the solution.

So I opened a command line or package manager console, chdir into the directory with the solution (.sln) file and just issued

C:> dotnet restore .\mySolution.sln

Problem was fixed.

Upvotes: 55

Crazy Cat
Crazy Cat

Reputation: 1462

My fix, and note that I did not have to delete or restore anything:

  1. Closed/reopened Visual Studio and reopened the project.
  2. Build/Clean Solution.
  3. Build/Rebuild Solution.

That was it – error was gone.

Upvotes: 0

SDanks
SDanks

Reputation: 681

In my case, the .csproj file existed, but there was an error that it could not be found. I used an editor like Notepad++ to open up the .sln file and found the reference to the .csproj file and edited it to point to the file. Saved it and double clicked the .sln file and it worked.

Upvotes: 0

George Saca
George Saca

Reputation: 90

I fixed this by doing the following: -> Solution explorer -> right click on Solution -> Properties -> Configuration Properties:

  • In the list, search the project that is generating this error (the one that references not the one referenced)
  • Check the build box and click Apply (If it's checked already then uncheck & apply, then check & apply)
  • restart Visual Studio & Build

Upvotes: 0

OfirD
OfirD

Reputation: 10490

Not mentioned in other answers:

I faced this issue with a project having <ProjectReference> items - but those projects were not compiled. Compiling them solved the issue.

  • Naturally, VS should have displayed an error indicating it can't find the dlls, but it instead displayed an error saying it can't find the csproj files, which is false.

Upvotes: 0

muhammad tayyab
muhammad tayyab

Reputation: 822

For me I had added wrong path in <ProjectReference Include=" for my *.csproj file. As I added correct path the problem was fixed.

Upvotes: 0

Rihah
Rihah

Reputation: 29

I had same issue and tried suggestions posted here, if reloading the solution and then unload a project in a solution but didn't work. Then I tried removing Projects from .csprj, compiled one more time and added in dependencies as a assembly instead of Projects. Worked for me.

Upvotes: 0

user3625699
user3625699

Reputation: 164

For me it was that there was a transitive dependency in Solution A from a shared project B to another shared project C which was not added to the solution. When the referenced project C was added to solution, the problem was fixed. The problem was not arising in Solution A before due to the fact that the library B had been always compiled in another solution D where the project C had been added. The problem had arisen because I cloned all projects fresh from git on new PC where none of these have been compiled before.

A: B -> C

D: B -> C

Short: make sure that the project which raises the error is added to the current solution.

Upvotes: 0

Mr Segfault
Mr Segfault

Reputation: 11

In my case I needed a reference to another project that is not part of the module's solution (We're using the ABP Framework - so referencing the *.shared project in the host's solution)

Here's what worked for me:

  1. Clean your solution(s)
  2. Close Visual Studio and delete the .vs folder(s)
  3. Add the reference to the .csproj file
  4. Rebuild the referenced .csproj project first
  5. Then rebuild the project that contains the reference
  6. If you still get this error, I've also opened up a terminal and ran the dotnet build command.

I hope this helps someone.

Upvotes: 1

rare_exception
rare_exception

Reputation: 11

I recently had this issue with the latest version of rider. I knew that the project reference was correct, because I have another solution pointing to it and that project is building just fine.

I ended up opening the console in rider and running 'dotnet build' manually. After that build succeeded, the rider ui-based build function stopped giving me this error.

Upvotes: 1

Артем Шиман
Артем Шиман

Reputation: 11

Just use: "dotnet restore MySolution.sln", Where MySolution.sln is your solution.

Upvotes: 1

Gokce Demir
Gokce Demir

Reputation: 685

Open powershell and running restore command solved my issue.

dotnet restore Sample.sln

Upvotes: 18

Mohammad Rajabi
Mohammad Rajabi

Reputation: 41

In my case I did it and it worked for me

  1. goto Tools/CommandLine/Developer Command Prompt or Developer Powershell
  2. type this command and Enter "dotnet restore".
  3. Build your solution

That's all

Upvotes: 2

ed22
ed22

Reputation: 1237

This happend to me when I had files with names exceeding OS's max path limit. Check your names ;)

Upvotes: 2

user2948533
user2948533

Reputation: 1173

After spending 3 hours, trying out numerous solutions, what worked for me is that I had to undo my root solution sln file...some of the project references were removed..not sure how.

Upvotes: 0

Urmo
Urmo

Reputation: 21

This is insane, i tried all this: updated VS. manually deleted all bin folders, run dotnet restore, clean rebuild nothing works

solution: finally i unload all the projects and start reloading them into solution, one by one in the order they show dependency errors. then the last one just cascade fixes everything. No idea what was wrong

Upvotes: 2

Jessica Downum
Jessica Downum

Reputation: 21

I correct this error by simply running the clean solution option. Right click the solution in the solution explorer and choose clean solution.

Upvotes: 2

itim
itim

Reputation: 437

I have next project structure (.Net Core projects):

../classLib
../../../webProject1
../../../webProject2
../../myWebProjects.sln

webProject1 and webProject2 reference classLib as project itself (not as .dll). When I opened my solution in VS 2019 and tried to build I got identical error NU1105: Unable to find project information for '../classLib.csproj'. error.

Before build depended projects you need to restore there dependency. What I did, just add next Target to my webProject1.csproj and webProject2.csprojfiles.

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="dotnet restore" />
</Target>

Upvotes: 3

Adam
Adam

Reputation: 4580

I encountered this error when having a duplicate reference to a project.

<ProjectReference Include="..\ProjectA.csproj" />
<ProjectReference Include="..\ProjectA.csproj" />

Removing the duplicate reference resolved the error.

Upvotes: 7

Raj
Raj

Reputation: 1

I was getting this error error NU1105: Unable to find project information for 'C:\folder2\project1.csproj'. but project1 that I had as part of the solution was located in C:\folder1\project1.csproj (it was also there in c:\folder2\project1.csproj too but not part of the solution, so it was confusing) Once I changed the reference to the correct location of the project it worked.

Upvotes: 0

Alexander Immanuel D
Alexander Immanuel D

Reputation: 106

Reload the project which causes the problem, this will fix the issue,

As mentioned in the following link :

https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1105

Upvotes: 1

Wil
Wil

Reputation: 11

I recently came across Error NU1105 while using JetBrains Rider on Linux. So this involves Mono and the MSBuild version that comes with it.

It turns out this was being caused by my solution files being in a directory that was a symbolic link to another directory. I believe MSBuild was dereferencing the linked directory and instead referencing the source directory. This makes some of the referenced paths completely different, even though they are the exact same files, case, everything else. Opening the solution from the original location works perfectly now for me.

Upvotes: 1

Kevin Brydon
Kevin Brydon

Reputation: 13112

What worked for me was to

  1. Remove the offending project
  2. Build the solution
  3. Re-add the project.

Upvotes: 5

Tyson Williams
Tyson Williams

Reputation: 1725

This error message will also occur if a referenced project is not included in the solution. I encountered this problem today, and I found the fix here.

Upvotes: 18

FindOutIslamNow
FindOutIslamNow

Reputation: 1236

Seems that some projects were removed from solution file (don't know why). Fixed by undoing these solution file changes

Upvotes: 3

Chris
Chris

Reputation: 565

For me, the casing of the project file on disk did not match the casing in the solution file.

Say I had a solution with LibraryA.csproj and LibraryB.csproj, where LibraryB.csproj has a reference to LibraryA.csproj. Having an incorrect casing for LibraryA.csproj in the solution file would cause NU1105 when building LibraryB.csproj:

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

I started seeing this problem after upgrading to version 15.5 of Visual Studio 2017. I did not encounter this problem with version 15.4.5.

Upvotes: 28

Related Questions