Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio 2017 not treating csproj as a valid project file after conversion from netstandard to framework

The following was done in VS Enterprise 2017 15.8.2. I had converted a .NET Framework project (C#) into netstandard and then had to convert it back due to a build issue. The conversion was done by restoring a previous commit from git. However, now VS does not recognize the project as a valid project. The linked unit test project generates the warning

the referenced component '< project name >' could not be found.

Attempts to view the project properties produces the error

An error occurred trying to load the project properties window. Close the window and try again. Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

The build selection options disappear from the build menu and the build/debug options are gone from the project context menu. The dependencies node of the solution explorer is empty. I have seen other posts in which people describe a similar condition that is resolved by either reopenning the solution or changing the mode of vs to a different type of development or deleting bin/obj. None of these worked, nor a full reboot. Given that this project file used to be framework I suspect there is something cached somewhere that is covered by my .gitignore which needs to be deleted.

like image 597
Tedford Avatar asked Sep 04 '18 22:09

Tedford


People also ask

How do I access Csproj file in Visual Studio?

Right-click on your project in solution explorer and select Unload Project. Right-click on the project (tagged as unavailable in solution explorer) and click "Edit yourproj. csproj". This will open up your CSPROJ file for editing.

How do I open a .csproj file in Visual Studio 2017?

Double-click the . csproj file to open it in Visual Studio. See Start from a Visual Studio solution or project. If the code is from another development environment, there's no project file.


2 Answers

Ran into the same issue myself. Appears to be an issue with the solution file. I removed the project from the solution then added it back again. This cause VS to recognize this as the correct project type. Hope this helps somebody else from spending too much time on this issue.

like image 148
bbent Avatar answered Oct 19 '22 18:10

bbent


Low level alternative to @bbent. Results in the same end result.

Open the sln file with a text editor and specify the matching PROJECT-TYPE-GUID for your project. the format is:

Format:

Project("<PROJECT-TYPE-GUID>") = "<proj name>", "<proj file path>", "<unique project guid>"
EndProject

Example for Classic C# Project:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibOne", "LibOne\LibOne.csproj", "{D5590E95-BFCC-4939-9D15-685D25B6BBE7}"
EndProject

Example for netcore, respective SDK-Style Project:

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibTwo", "LibTwo\LibTwo.csproj", "{D5590E95-BFCC-4939-9D15-685D25B6BBE7}"
EndProject

The project-type-guid is a GUID (defined my MS) which stands for ('c#', 'c++', 'xna', 'folder', 'web site', etc).

excerpt:

C#          {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
folder      {2150E333-8FDC-42A3-9474-1A3956D46DE8}
core        {9A19103F-16F7-4668-BE54-9A1E7A4F7556}
wpf         {60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}
  • Stackoverflow Answer with several Project-Type-Guids and explanation
  • full list at codeproject

There's nothing official from microsoft though! The complete list is probably only in the Visual Studio sourcecode. But the IDs don't change, at least not in the last decade.

like image 44
juwens Avatar answered Oct 19 '22 18:10

juwens