rollsch
rollsch

Reputation: 2780

csproj keeps losing referenced project references in VS2017 using new csproj format

My csproj has the following lines:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <Deterministic>False</Deterministic>

  <ItemGroup>
    <ProjectReference Include="..\blah.Common\blah.Common.csproj" />
    <ProjectReference Include="..\blah.Model\blah.Model.csproj" />
  </ItemGroup>

The referenced projects build fine. However in the VS tree these two projects randomly disappear from the Dependencies tree and VS reports the references as missing and the build passes.

Reloading/rebuilding/cleaning/restarting/removing then adding the projects again in no particular order usually fixes it. Problem comes back after a legitimate build error crops up in another project.

I am using Resharper and VS2017

I have tried dotnet restore with no luck. Any ideas why this one particular project is constantly losing its references?

Edit: I just realised I incorrectly mentioned the build as FAILING. It does not fail and builds successfully, however my project is litered with red errors and warnings saying references are missing. After a successful build the red warnings/errors disappear then randomly come back again.

Sometimes the projects are literally missing from the references tree, other times they are visible. When right clicking "add reference" the project is already ticked however. Unloading the project and reloading or doing a full rebuild fixes the "Error" only for it to come back at some point.

Even though the "Error List" is filled with missing reference errors, a clean and full build produces no errors and creates a successful build.

Upvotes: 4

Views: 2354

Answers (1)

ThePretendProgrammer
ThePretendProgrammer

Reputation: 1517

Did you check the .NET framework version that these 3 projects are targeting?

Incompatibility between framework versions allows the reference to get added but results in missing references during build/run time. To validate if this is indeed the problem, you can check the warnings that Visual Studio produces while building the solution. An alternative way of finding the root cause of the problem, would be to add one of the projects as a DLL reference while keeping the other as a project reference. If the DLL reference doesn't work, it means there is some configuration mismatch between the source and target projects (e.g. .NET framework version). If the DLL version works, then it means Project References are broken, in which case you can check if path provided is correct.

Upvotes: 4

Related Questions