Jeroen
Jeroen

Reputation: 63830

Visual Studio 2017 not able to resolve any using statements

I'm using Visual Studio 2017 (Enterprise, 15.6.6 at the moment), and no solution seems to load correctly anymore. A specific, simple repro on my environment is to open Visual Studio and create a new "ASP.NET Core Web Application (Visual C#)", subtype "API" without authentication or docker support.

If I then open Startup.cs I'm greeted with a screen filled with red squiggly lines under all using directives and corresponding usages of stuff from those namespaces:

red squiggly lines everywhere

If I restore NuGet packages it will say something along these lines:

Restore completed in 52,93 ms for ....WebApplication1.csproj.

If I build the solution I get a bunch for errors about references not being found. I then checked the "Build" Output window and it says something along these lines:

------ Build started: Project: WebApplication4, Configuration: Debug Any CPU ------
[...] The "ResolveAssemblyReference" task failed unexpectedly.
[...] Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Unexpected CopyLocal flag.
[...]    at Microsoft.Build.Tasks.CopyLocalStateUtility.IsCopyLocal(CopyLocalState state)
[...]    at Microsoft.Build.Tasks.ResolveAssemblyReference.LogResults(ReferenceTable dependencyTable, DependentAssembly[] idealAssemblyRemappings, AssemblyNameReference[] idealAssemblyRemappingsIdentities, ArrayList generalResolutionExceptions)
[...]    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, OpenBaseKey openBaseKey, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader)
[...]    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute()
[...]    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
[...]    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "WebApplication4.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped  ==========

The abbreviated bit at the start of each line (not sure if it's relevant) is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2052,5): error MSB4018: 

Now most likely something I've done recently caused this to appear. Some things I suspect are:

I'm at a loss of what the problem could be, or more importantly: how I can find out what the problem is. So my main question is: how do I attack this specific problem? Failing that, my question is how to solve this situation (though I suspect there can be multiple causes).

Upvotes: 1

Views: 1398

Answers (1)

Jeroen
Jeroen

Reputation: 63830

After writing the question I did a few hail mary fixes, including purging this:

c:\users\jeroen\.nuget\packages\*.*

This technically only answers the second question. I'm posting this because it might help someone, but I'm still oblivious to the actual cause or a good heuristic for solving this type of issue, and would love to see another, better answer.

Upvotes: 3

Related Questions